Archive:PHP and MySQL Programming/Syntax Overview: Difference between revisions
wikademia>Kencyber No edit summary |
wikademia>Wikademia m moved PHP and MySQL Programming/Syntax Overview to Archive:PHP and MySQL Programming/Syntax Overview over redirect |
||
| (12 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
== PHP tags: == | == PHP tags: == | ||
{{ntnes}} | |||
=== '''<?php [code] ?>''' === | === '''<?php [code] ?>''' === | ||
* Enclose php code | * Enclose php code | ||
* Can be configured in the php.ini to be <? ?>, <script language="php"> </script> etc. | * Can be configured in the <code>php.ini</code> to be <code><? ?></code>, <code><script language="php"> </script></code> etc. | ||
* Embedded in normal HTML code | * Embedded in normal HTML code | ||
| Line 15: | Line 15: | ||
<source lang="php"> | <source lang="php"> | ||
<?php | <?php | ||
print | print "Hello World\n"; | ||
$date = date( | $date = date("Y-m-d H:i:s"); | ||
print | print "The date and time at the moment is $date"; | ||
?> | ?> | ||
</source> | </source> | ||
| Line 41: | Line 41: | ||
<source lang="php"> | <source lang="php"> | ||
<?=date( | <?=date("Y-m-d H:i:s")?> | ||
</source> | </source> | ||
Which will output something like ''2005-11-09 19:40:05''. | Which will output something like ''2005-11-09 19:40:05''. | ||
[[]] | |||
== Commenting == | == Commenting == | ||
| Line 54: | Line 55: | ||
* Example: | * Example: | ||
<source lang="php"> | <source lang="php"> | ||
echo | echo "Hello"; # Everything from the hash is commented out | ||
</source> | </source> | ||
| Line 186: | Line 187: | ||
* Example: | * Example: | ||
<source lang="php"> | <source lang="php"> | ||
$a = | $a = "Fill the halls "; | ||
$b = | $b = "with poisoned ivy..."; | ||
$c = $a . $b; # the '.' operator concatenates two variables. | $c = $a . $b; # the '.' operator concatenates two variables. | ||
// $c = | // $c = "Fill the halls with poisoned ivy..."; | ||
</source> | </source> | ||
| Line 211: | Line 212: | ||
// $a[3] = 4; | // $a[3] = 4; | ||
$b = array( | $b = array("name" => "Fred", "age" => 30); | ||
// $b['name'] = | // $b['name'] = "Fred"; | ||
// $b['age'] = 30; | // $b['age'] = 30; | ||
| Line 219: | Line 220: | ||
== Decision and Loop Statements == | == Decision and Loop Statements == | ||
'''IF THEN ELSE statement''' | |||
* Example: | * Example: | ||
<source lang="php"> | <source lang="php"> | ||
$a = 1; | $a = 1; | ||
$b = 10; | $b = 10; | ||
| Line 349: | Line 350: | ||
function who_am_i() { | function who_am_i() { | ||
echo "My name is {$this->name | echo "My name is {$this->name}, and I am a dog"; | ||
} | } | ||
} | } | ||