PHP/MySQL : First steps with PHP
Contents ]
Jean-Guillaume Birot

Creating a Dynamic Web Page

Now that you understand how everything works, we can create and test a new page called hello.php, which contains the following code:

<html>
<head>
<title>PHP Test</title>
</head>
<body>
  <H1 align="center">
<?php print("Hello world!"); ?>
</H1>
</body>
</html>

This code example is closer to that of a regular HTML page. Our PHP tag contains a call to the print function, to which a character string delineated by quotes ("Hello world!") is passed as argument. The role of this function is to print out the passed argument onto the browser window. This is an essential function since it is used to fill the HTML page with the content automatically generated by the PHP script.

Variation. You can also see in existing scripts the instruction echo, which acts like the print function, except that it does not require the argument to be passed between parentheses.

Make sure you always finish a line of PHP code with a semicolon. Inserting a carriage return will have no effect in the code.

Once you have placed the page in the appropriate location, open it in your browser and view the source of the HTML page. You will see that there is no longer any PHP tag and that the print function has correctly printed out the phrase. Here is the result you should obtain:

PHP test

Hello world!



For the record. Since the C Reference by Kernigham and Ritchie was published in 1978, any story between a programmer and a new language begins with a first program displaying "Hello World!"