Introduction to PHP

Updated: Friday 5th November 2010, 6:55 PT, AD

PHP stands for PHP: Hypertext Preprocessor.

PHP was created in 1994 by Rasmus Lerdorf as a software package which
was originally called "Personal Home Page Tools". 

Lerdorf originally created the PHP package to track visitors to his website.
PHP was designed specifically for interacting with the web. In fact, most
commonly, PHP statements are embedded directly into HTML or XHTML documents
(i.e. web pages).

PHP is currently one of the most popular server-side scripting languages
for creating dynamic web pages. 

PHP is:

PHP Introduction

PHP programming

PHP programming statements are embedded directly into HTML or XHTML documents.

Web pages containing PHP statements are normally saved with the file extension .php
but other extensions are sometimes used.

The PHP language has many of the same keywords as Python, 
e.g. while, for , if, break, continue, and, not, or etc.

PHP uses the same data types as Python: int, float, string, bool (Boolean) etc.

To run a PHP program (script), the PHP interpreter must be installed on your system
as well as web server software such as Apache.

PHP and Apache are free, open source and multi-platform.

PHP code is inserted anywhere in HTML/XHTML markup between the 
scripting delimiters <?php and ?>

Variable names must start with the $ character.

Variable names in PHP are case sensitive, i.e. $age and $Age are different variables.

PHP statements must end with a semicolon (;).

One-line comments can start with two forward slashes (//) or a # character.

Multiline comments start with the /* characters and end with the */ characters.

Output to the browser can be achieved using either the print or the echo statement.

Whitespace is ignored by the PHP interpreter, but is used to enhance readability
and to ease debugging (finding errors in the code).

Example PHP programs


Example of a web page calling a PHP program which accesses a database:

email me: if the Library link crashes
- it means either the IP has changed, the server is not on,
or the MySQL server has stopped. process_library.php

Please note: 

Database processing is not covered in this course.
The library system shown above is for illustration purposes only.

[see p364 of Web Programming in Python - 
Techniques for integrating Linux, Apache and MySQL by Thiruvathukal et al, 
Prentice Hall, 2002, ISBN: 0-13-041065-9]

Valid XHTML 1.0!

Valid CSS!