Anatomy of a PHP script

The basic outline of a PHP script consists of:

  1. PHP Opening tag
  3. Statements
  4. PHP Closing tag
  • File name ends .php


     //The infamous "Hello, World!"
     echo("Hello, World! \n") ;


PHP tag, informs interpreter to execute PHP code

<?php     ?>


Short codes <? ?> (without the php) can be used but are considered bad form



Use # or // for a single line
Use /* for

Multiple lines



In this case the echo() function outputs a quoted string (as its argument) within its parentheses.

NOTE: Each statement must end with a semi-colon ;


Forgetting the semi-colon, is one of the most common problems!!


Whitespace, to make code more readable

Leave a Reply