<HTML> <HEAD><TITLE>What time is it?</TITLE></HEAD> <BODY> The time is now <?php print(date("d/m/Y H:i:s",time())); ?> </BODY> </HTML>When this page viewed, the body would look something like:
The time is now 10/02/2001 20:06:07If you simply want to print out the contents of a value, and your php.ini file is configured for it, you can use:
The time is now <?=date("d/m/Y H:i:s",time())?>The <?php and ?> tags do not have to be on the same line.
One hard concept to grasp is that the <?php ?> tags are merely to delimit what is PHP code and what is HTML. The whole page is processed by the PHP module. So different parts of the same program can be in different <?php ?> tags, and even have HTML between them. So you can do things lile
Authorizing... You are <?php if(Authorized($UserName)) { ?> authorized. Please proceed. <?php } else { ?> <FONT COLOR="RED" SIZE="+2"> NOT AUTHORIZED! A security team has been dispatched. Please remain where you are. <?php } ?>This also means variables with global scope (declared outside of functions) have page scope, and can be referenced from different blocks of PHP code on that page.
$bar = &$foo;
$string = "date"; $t = $string("YMH");
$a = "hello"; $$a = "world"; # Same as $hello = "world" print("$a ${$a}"); # prints "hello world"
foreach(array_expression as $value) statement foreach(array_expression as $key => $value) statement
function Add ($arg_1, $arg_2) { return $arg_1+$arg_2; }