«^»
3.1. A simple example

Here is a simple example of a PHP script:

0001: <HTML><BODY>
0002: <?php
0003:    $numrows = 3;
0004:    for ($rownum = 0; $rownum<$numrows; $rownum++)
0005:    {
0006: ?>
0007:       <P>hello world</P>
0008: <?php
0009:    }
0010: ?>
0011: </BODY></HTML>
Suppose that the file hellothree.php contains this code. It can be executed by passing it to a WWW server that understands PHP. Click on the following link to see what happens: http://www.dur.ac.uk/barry.cornelius/papers/phpintro/code/hellothree.php

If a WWW server is configured to handle PHP, it will pass any file with a php extension to a PHP processor. The PHP processor knows it has to interpret the bits between the <?php and ?> symbols. When given the above script, the PHP processor will output the following HTML and this is what is sent to the visitor's browser:

0012: <HTML><BODY>
0013:       <P>hello world</P>
0014:       <P>hello world</P>
0015:       <P>hello world</P>
0016: </BODY></HTML>