Anatomy of a PHP script

The basic outline of a PHP script consists of:

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

 

PHP tag, informs interpreter to execute PHP code

<?php     ?>

 

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

 

Comments

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

Multiple lines
*/

 

Statements

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