PHP

(Home)

Top 3 Resources 
Resource PHP
Resource The PHP Resource Index
Resource PHP Freaks
Quick Referencek Reference
   
Code
Text To Screen <?php print "Hello, World!"; ?>
Create Variable <?php print $greeting, ", "; ?> World!
Variables <?php

$number = 5;
$string1 = "this is a string\n";
$string2 = 'this is another "string"';
$real = 37.2;

?>
Arrays <?php

$array1 = array(2, 3, 5, 7, 11);
$array2 = array("one" => 1, "two" => 2, "three" => 3);
$array3 = array(5 => "five", "six", "seven");

printf("7: %d, 1: %d, 'six': %s\n", $array1[3], $array2["one"], $array3[6]);

?>
Conditional Statement <?php

if ($a) {
    print "a is true<BR>\n";
} elseif ($b) {
    print "b is true<BR>\n";
} else {
    print "neither a or b is true<BR>\n";
}
?>
For Loop <?

for ($i = 0; $i < 10; $i++) {
    print "i=$i<BR>\n";
}
?>

While Loop <?

while ($d) {
    print "ok<BR>\n";
    $d = test_something();
}

?>

Do Loop <?

do {
    $c = test_something();
} while ($c);
?>

Comments // Conditionals
Cookies
if (!$myname) {
    print "What is your name? ";
    print "<FORM ACTION=\"$PHP_SELF\" METHOD=\"GET\">\n";
    print "<INPUT NAME=\"myname\" SIZE=20>\n";
    print "</FORM>";
    exit;
}

setcookie("myname", $myname);

?>