Variables:

Set up the variable:

<? php

$webTitle = 'Trick or Blog';

$pageTitle = 'Something';

?>

Echo the variable back in your document:

<h1> <? php echo $webTitle; ?> </h1>

PHP Globals:

Globals can be used on many or all pages. Save req_globals.php so you can call it where needed:

<? php

require_once('req_globals.php');

?>

PHP Includes:

Different than globals as its more of a template solution. For example for a navigation bar, save code in new document as mainmenu.php. Then call it in your main document wherever needed.

<? php

include('mainmenu.php');

?>

PHP Strings:

A string is the text part of the code between the parenthesis.

$str1 = 'This part of the code is called the string';

Concatenation:

Use a period to separate strings.

Example: $String1 . 'What' . $String2;

echo $myString;

echo $myNumber;

Mathematics:

You must use algebraic form parenthesis to force proper order.

echo $num1 + $num2 - $num3 / $num4 * $num5;

Conditionals:

Set up conditionals so variables can change the outcome.

<? php

if (false)

{

echo'<img src = " " />';

}

?>

 

<? php

$youarecrazy = 'yes';

if $youarecrazy = = 'yes';

{

echo '<img></img>';

}

else

{

echo ' ';

}

?>