Introduction to PHP for Os X by Example

So What’s Inside the Program?

001 <?php 002 $title = 'Hello X World III'; 003 ?> 004 <html> 005 <head> 006 <title><?php print $title ?></title> 007 </head> 008 <body> 009 <h1><?php print $title ?></h1> 010 <?php 011 phpinfo(); 012 ?> 013 </body> 014 </html>

Line 1. The opening PHP tag <?php tells the server / PHP interpreter that the following content is PHP.

Note: In older versions of PHP it was considered reasonable practice to use the short form of the opening PHP tag, <?. However, this is no longer the case, and many systems will ignore the short form of the tag. So to be on the safe side its best to use the accepted long form.

Line 2. Assigns the string 'Hello X World III' to the variable $title.

Line 3. The closing PHP tag, ?>.

Line 4-5. Standard HTML code.

Line 6. Contains a small section of in-line PHP code that prints the $title variable.

Line 7-8. Standard HTML code.

Line 9. See line 6.

Line 10-12. A small multi-line section of PHP code that simply invokes the phpinfo() function. Seeing the output of this script is the best way to understand what it does.

Line 13-14. Standard HTML code.