Using PHP in CSS322

PHP is typically used for creating dynamic web pages. We are going to use it as a simple interactive language for several reasons:

We will use the command line interface of PHP (not the web interface). Hence to develop your code you should follow these instructions.

Installation

PHP is available for free download from http://www.php.net/.

For Windows, select the PHP 5.2.6 Installer from the Windows Binaries (approximately 20MB). This will be downloaded from a local Thai mirror. Perform the standard install. You do not need to configure a Web Server, and the standard packages (those selected by default) are sufficient. This includes the command line interface.

On Ubuntu Linux, PHP is usually installed by default, but you need to install the package php-cli (the command line interface):

sudo apt-get install php-cli

On other Linux distributions there is probably a similar package - try your distribution's package repository.

Using the PHP Command Line Interface

Open a command prompt in Windows (cmd) and change to your working directory, e.g.

cd C:\Documents and Settings\Steve\My Documents\CSS322

You can execute PHP code from the command line or from a file, e.g.

php -r "echo 'hello';"

will print out the word hello. Or if you create a text file test.php with the following contents:

<?php
echo 'hello';
?>

and then run:

php test.php

then the word hello will be printed.

I recommend you put all of your code in a single file and use the second approach for executing PHP code.

Documentation

The manual, including all function references, for PHP can be found at: http://www.php.net/manual/en/. Some specific pages that will be useful to you include:

Return to: Course List | Steven Gordon's Home | SIIT