Acronym for PHP
PHP Hypertext Preprocessor
Original acronym for PhP
Personal Home Page
Basic output statements in Php
Echo and print
Variable names are case sensitive.
YES or NO ?
Yes
$_GET
contains value of input being transported through GET method
$_ENV
contains server environment variables
String Concatenation
$string3 = $string1 . $string2;
Function ‘filetype’
checks if it’s a file or directory
echo "/etc/passwd is a " . filetype('/etc/passwd');
// is a file
echo "/etc is a " . filetype('/etc'); // is a dirFunction ‘gettype’
checks the type of variable $var1 = 5; // integer echo gettype($var1);
‘header’ function
used to redirect browser to another location
header(“Location: http://ict.senecacollege.com”);
$_SERVER[“REMOTE_ADDR”]
$_SERVER[“SERVER_NAME”]
$_SERVER[“SERVER_ADDR”]
User’s IP address
Server’s name:
Server’s address
strlen() function
to return the length of a string
strpos() function
to search for a character/text within a string
echo strpos(“I love Linux”,” Linux”); //returns 7
Date functions
// to show date in numbers eg. 21 11 10
echo date("d m y");
// to show date in numbers with hyphen separators eg.21-11-10
echo date("d-m-y");
// to show date in words eg. Sun Nov 2010
echo date("D M Y");Time functions
//time (12 hr clock) separate by colon using a date function
echo date("h:i:s");
//time (24 hr clock) separated by colon using a date function
echo date("H:i:s");function ‘decbin’
converts decimal to binary
function ‘bindec’
converts binary to decimal
Associative Arrays
$ages=array(“Peter”=>32, “Jim”=>30, “Ken”=>34);
echo “Peter is “ . $ages[‘Peter’]. “years old”;
Difference between: include() and require()
program will continue executing if the filename you pass to include() does not exist, while require() will stop executing if the filename you pass does not exist