About This Site

When we were learning PHP, we scoured the Web for exercises to help us develop our skills and came up empty. Thus the inspiration for this site.

All scripts have been tested and their output validated as transitional XHTML.


First, you will see the instructions for writing your script. Write and test your script, then click the "View Script" button. You will then see the answer script. Below the code is a link to live output from the script, so you can see if yours behaves the same.

The text of the exercise instructions is included above the answer script in italics. Some exercises have two parts. The second script includes the instructions for both the first and second scripts. In answer scripts, the name "yourfile.php" fills the place of the actual name of your own script.

Some of the text in the PHP exercises, usually what you will need to print to the browser, is highlighted in yellow. This is done only to make it easy for you to see. It does not mean you should highlight text in your scripts.


As of June 2016, this site has been upgraded to Drupal 7. The syntax highlighting on the Drupal 6 site, based on Alex Gorbatchev library SyntaxHighlighter, works differently in Drupal 7 and was not an option for the main scripts shown in the exercises. Those are now formatted using the GeShi filter.

Code in comments also required a new approach. The GeShi filter does not have a collapse option like the Gorbatchev highlighter. But in Drupal 7, the Gorbatchev highlighter requires every left angle bracket (<) to be converted to an HTML entity (&lt;). In some comments, that's an enormous amount of work. So we've reversed the order of the comments to show oldest first and edited those at the top to work with the collapsible highlighter. This frees new comments to be formatted with either of the highlighters, since they will appear farther down the page away from the exercise.


If you find mistakes, please, let us know! Typos, grammar, anything. Send us an email.

Site Structure:

Phpexercises.com is built on Drupal 7. Click the logo in the footer for a link to drupal.org. Nancy is also a past member of the Drupal Association, jn2 on drupal.org, who provides Drupal services.