Consider the following extract from a PHP-driven web page that displays the current date :
Today is <?php echo date (' j F Y '); ?>
The <? php tag tells PHP that everything that follows is program code rather that HTML, until the closing ?> tag. In this example , the echo command tells PHP to display the next item to screen; the following date command produces a formatted version of the current date, containing the day, month, and the year.
in this blog i will use defualt tag <?php …. ?> , but other tag styles can be used, so you may come across other people’s PHP code beginning with tags that look <? ( the short tag), <%(the ASP tag style or <script language=”php”> (the script tag).
Of the different tag styles that can be used, only the full <?php tag and the script tag are always available. The others are turned off or on by using a PHP configuration setting. We will look at the php.ini configuration file .
Anything that is not enclosed in PHP tags is passed straight through to the browser, exactly as it appears in the script. Therefore, in the previous example the Today is appears before the generated date when the page is displayed.
Your First Script
Before you go any further, you need to make sure you can create and run PHP scripts as you go through the tutorials in this blog. This could be on your own machine, and you can find the tutorial about installing the Apache server and mysql database system here .
Now go ahead and create a new file called time.php that contains this code :
<title> My First Script</title>
The time is <?php echo date ( 'H: i: s' ); ?> and the date is <?php echo date (' j F Y' );?>
now you can test you by typing this URL http://localhost/time.php
The time is 17: 20: 12 and the date is 1 December 2008