PrimitiveType

An Overview of PHP

PHP (a recursive acronym for PHP: Hypertext Preprocessor) is a scripting language used primarily to power dynamic web sites, though it can also be used for other purposes. The common extension for PHP files is .php, though others such as .php3 exist too, and in web servers such as Apache, it is possible to configure the server to treat files with other extensions as PHP scripts as well. The latest release version of the language is PHP5, though PHP4 retains widespread use and support. PHP 6 is in development.

The PHP logo
The PHP logo

PHP was originally created by Rasmus Lerdof in 1995 as a set of tools he could use to display his online CV and monitor traffic to his website, and PHP originally stood for the first three words of his Personal Home Page Tools. From a set of Perl scripts, PHP was ported to C, the language behind PHP to this day. In 1997 PHP was recoded by the Israeli developers Zeev Suraski and Andi Gutmans, who would later form Zend Technologies and release the Zend Engine as the C core on which PHP is based.

The release dates for the main revisions of PHP are:

  • PHP/FI 2 June 1997
  • PHP3 June 1998
  • PHP4 May 2000
  • PHP5 July 2004

PHP is considered easy to learn in comparison to Java and many other programming languages, though many also consider it to be less industrially powerful. In fact, whilst PHP is incredibly popular, you will find that many major business sites opt for other technologies and platforms. It is easy to see why many corporations trust Java over PHP, with its foundation in a major technology company, Sun Microsystems, versus PHP's origins as a set of scripts for the personal use of just one programmer. However, PHP has a huge community behind it and has become a mature web programming language in its own right.

An example that demonstrates PHP's ease of use is the mail() function. Using this function, sending email from within a PHP script involves a single line of code. Another example is the file_get_contents() function, which, again with a single line of code, can be used to retrieve the contents of a file, even a remote, publicy accessible file, into a string.

A simple PHP program that displays the phrase "Hello, World!" can be written as follows:

<?php print "Hello, world!"; ?>

In its default set up, PHP is interpreted and compiled into intermediate code that the Zend Engine runs each time a request for a script comes in. The specifics of this process can be changed with code accelerators and optimizers.

PHP is maintained by The PHP Group and is open source and free. As a result, PHP hosting can be provided at low cost, a contributing factor to PHP's popularity. The PHP Group runs the central website for PHP resources, www.php.net, where you can download PHP, read user manuals and go through the tutorials to get you started.

PHP borrows extensively from C, Perl and, more recently, Java. The basic C-syntax is followed in PHP, and many of PHP's functions are wrappers to C functions that share the same name. Like Perl, PHP can embed variables directly in a string without needing to close the string off with quotation marks & then concatenating. PHP's object orientation support has been modeled closely on that of Java, especially as of PHP 5.

The other ways in which PHP can be used are from a command line interface and in graphical user interface applications, though the latter in particular is rare.

Some recommended PHP books:
Programming PHP
Build Your Own Database Driven Website Using PHP and MySQL
Advanced PHP Programming