Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

PHP Function With More Than One Value

PHP Function With More Than One Value
 
This article will try to explain how to create a function that can return more than one value, or Returning multiple values from function in PHP. The essence of these functions is the use of arrays and list (); function. Here I will try to give an example function that can separate the first name and last name of a person's name. Create a file named value.php or you can give another name that you want.
 
The contents of the file with:
< ?php
function double_value($fullname)
{
$firstlast = explode(” “, $fullname);
$first_name = $ firstlast[0];
$last_name = $ firstlast[1];
return array($first_name, $last_name);
}
$myfullname = “John Lennon”;
list($myfirstname, $mylastname) = double_value($myfullname);
echo “Full Name : “.$myfullname.”<br>”;
echo “First Name : “.$myfirstname.”<br>”;
echo “Last Name : “.$mylastname ;
?>

The core of its functions :
When a variable used as the contents of the parameter :
double_value ($fullname)
Separate the first and last name by using a space and enter into an array :
$firstlast= explode ("", $fullname);
So that later can be able to access the first name we can use variable $firstlast[0]
and to access last name we can use variable $firstlast[1]
Then do the return value of the form array :
return array ($first_name, $last_name);
With the list() function take two values that shaped an array :
list ($myfirstname, $mylastname) = double_value ($myfullname);
Then show by using echo function :
echo “Full Name : “.$myfullname.”<br>”;
echo “First Name : “.$myfirstname.”<br>”;
echo “Last Name : “.$mylastname ;
That is one example of the algorithm makes the function can return two values.

PHP Function With More Than One Value

PHP File Functions

PHP File Functions

integer fopen (string filename, string mode)

This function is used to open the file before writing or reading the contents of the file.
For example:

Preventing Direct Access In PHP

Preventing Direct Access In PHP Files

To prevent direct access can be used redirect method. Redirect is actually can be exploited when a user has done filling the form, then redirected to a page that contains information that the form has been filled correctly, and other information. This tutorial discusses the more about the PHP file itself. What I mean here is about accessing a PHP file directly.

Automatic Logout Session

Script timer Session, Automatic Log Out

Many things happen if someone has managed to login as a user, and of course this is when the user login will utilize the services of a website, not because of other reasons, such as poor levels of security. There is always an idle period. Idle here means users do not do anything at all on the website, did not move a page, do not enter any input on the form, and nothing cause a web page refresh, in other words a user does not do anything on the website through which he was visiting. 

PHP Security


PHP Security - Check Bug in PHP Script  

After finishing PHP scripts that we have made there are times when the bugs are unwanted fester on the sidelines of the script that was ready to be online. And of course this bug can be fatal so it can be used by the intruder, intruders who try to exploit the system.

PHP : Echo or Print

PHP : Using Echo or Print
 
When we write a program using PHP, we often use echo and print commands, but we do not know what is the effects of using echo or print. Sometimes we can be dizzy between two options, use echo or print when you want to display the contents of a variable, or just display text alert than usual as a process that has been done. Echo or Print? Echo or Print? Echo or Print? and so on ... A little confused indeed. In addition to the print and echo, PHP also provides many alternatives for the other syntax.

Simple Captcha with PHP


Simple Captcha with PHP
 
Captcha is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart" (Wikipedia), and made to distinguish between machines (bots) and human.

PHP Array Sorting

PHP Array Sorting

The values contained in the array can be sorted, for numeric values are sorted from lowest to highest value while for the string will be ranked from a to z. To sort the values used sort() function with the terms of the array elements are integers, for the array with string element can be used asort() function.

PHP String Manipulation 2


PHP STRING MANIPULATION part 2

chr ()

chr () function is used to translate the ASCII code. For example:
echo (chr (34); / / Will produce the sign "

PHP String Manipulation 1


PHP STRING MANIPULATION part 1

In PHP there are some functions that can be used to manipulate strings for example, to replace certain characters, remove spaces, and others. The following are the functions that are used in PHP to manipulate strings.

PHP File Operation


PHP FILE OPERATIONS

To open / access the files in PHP you can use fopen (). The function fopen () can access files from the file system, or via HTTP or FTP on the Internet.
The syntax is:
 fopen (filename, access mode);

PHP Function


How to make function in PHP

Function or a number of statements that are packed in a name. This name can then be called multiple times in several places in the program.
The purpose of the use of the function is:
  • Facilitate in developing programs
  • Reduce the size of the program
To create a function, must follow the syntax as follows:

PHP For


PHP For Repetition

As with other programming languages, PHP also provides the facility to perform repetition. One way is to use a For. Write this example below :

PHP Boolean


PHP Boolean Values

Boolean values are typically used in program control structures, such as if or If-Else. There are several conditions must be in use Boolean values, namely :

PHP While


While Repetition in PHP

In addition to the For ', we also can do the loop by using a While.
Here is an example how to use while in PHP :

PHP Switch


PHP Switch Statement

Switch statement is used to compare conditions with different values.
<?
$age = 2;
switch ($age) {
       case 1:
             echo "The baby was still very small";
             break;
       case 2:
             echo "The baby was already very lively";
             break;
       case 3:
             echo "The boy was already apparent intelligence";
             break;
       case 4:
             echo "The boy was very happy to enter kindergarten";
}
?>

PHP IF and IF-Else


PHP IF and IF-Else
IF StatemenetIF is used to check whether a condition in if met, if yes, an operation performed, consider the example below:
<?
$ name = 'castle';
if ($ name == 'castle') {
       echo "My home is $name";
}
?>

PHP Object Data Type


Object Data Type

Object is a data type that can be either a number, variable even a function. Objects created with the intent to assist programmers who are familiar with OOP (Object Oriented Programming), although the facilities provided OOP PHP is still very limited.
Consider the example below object.php:

PHP Array


PHP Array

Array is a type of structured data that is useful to store some of the same type of data. Parts that make up the array called array elements, each element can be accessed separately through the array index.

One-Dimensional Array
<?
$country[0] = "England";
$country[1] = "France";
$country[2] = "United States";
$country[3] = "Japan";

print ("I live in $country [2]");
?>

PHP Operator


PHP OPERATOR

The operator is useful to perform an operation on a value. Operators in PHP is very common so it is easy to understand. Here we will discuss the service that is often used.

Arithmetic Operators
$ x + $ y; / / for the summation
$ x - $ y; / / for the reduction
$ x * $ y; / / for multiplication
$ x / $ y; / / for division
$ x% $ y; / / for the rest of the results for (modulus)