PHP Tags
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 :
<html>
<head>
<title> My First Script</title>
</head>
<body>
The time is <?php echo date ( 'H: i: s' ); ?> and the date is <?php echo date (' j F Y' );?>
</body>
</html>
now you can test you by typing this URL http://localhost/time.php
Output
The time is 17: 20: 12 and the date is 1 December 2008
December 2, 2008 at 8:44 pm |
Hi Ibrahim, nice page I’ve been looking for something like this, just a step by step practicing. I’m a Cameroonian(Central Africa) student in Germany, but i actually study Mechanical Engineering, so I’m a newbie to this, but I’m facinate from coding and would like sometime to buy my own Application or customize some opensource…So I feel like, i’m at the righ place. So just Kudo. Cheers
December 2, 2008 at 8:45 pm |
By the way, I’m frenchspeaking motherlanguage, so don’t wonder about my english.
December 2, 2008 at 9:12 pm |
No no nothing wrong with your English as long as i get your feedback …
Just wait for the second lesson …. see yeh..