Lesson 1 : Getting to know PHP [part 2]

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 :

<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


3 Responses to Lesson 1 : Getting to know PHP [part 2]

  1. Omer says:

    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

  2. Omer says:

    By the way, I’m frenchspeaking motherlanguage, so don’t wonder about my english.

  3. joker400 says:

    No no nothing wrong with your English as long as i get your feedback …

    Just wait for the second lesson …. see yeh..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: