Академический Документы
Профессиональный Документы
Культура Документы
<?php ?>
echo similar to print
print prints to screen
"Hello" . " World!" String concatination with a period
$ Use at the start of a variable (variables are case
sensitive with no spaces)
echo "<br />"; creates a break in the lines.
echo "Hello World<br />"; Strings can contain html line breaks and can be done
in single quotes.
echo "{$variable} Again"; This also concatinates but can only be done with
double quotes.
echo $variable."Again";
<br /> This line break can be used outside of php in the
html side.
Name: Returns the name and output when echo is used.
Function to strings
Numbers
echo $string1 = implode(" * ", $array1); Takes the values from an array and
creates a string sperated by asterisks
print_r (explode(" * ", $string1)); Takes a string and seperates the elements
at the asterisks and creates an array.
in_arry(element, array) Searches for an element in an array and
returns nothing or a 1 for F/T
Boolean
Typecasting
IF statements
if(expression) {statements;} If statements evaluates as a boolean
expression
elseif(expression) {statements;} elseif
else{statements;} else
Switch statement
switch ($a){
case 0:
echo "a equals 0"
break;
case 1:
echo "a equals 1";
break;
case 2:
echo "a equals 2";
break;
default:
echo "a is not 0, 1 or 2";
break;}
Loop Statements
while(expression) {statements;}
$count ++;
For Loop
Pointers
Function
function name(arguments){statements;}
Return Values
Debugging functions
echo $variable;
print_r($array)
gettype($variable);
var_dump($variable); Gets variable type and value.
get_defined_vars(); Returns an array of all defined variables.
Creating websites
Global Variables
_POST
Used along with forms. This is also in the
form of an associative array.
$username = $_POST['username'];
Session is file stored on webserver. Can store more info but lasts shorter than
cookie. Needs to be used as a header. Keeps info on server and not on user name.
When using header information in the body. Headers are usually before
html tags, but can use this code to initiate the output buffer
The following starts the output buffer to include headers and cookies in the body
of the html.
ob_start();
<html>
</html>
ob_end_flush();
if (!$connection){
die("Message: " . mysql_error()); To avoid returning errors
when using require_once.