PHP Hypertext Preprocessor

The remarkable volume of information which has moved to the Web over the last few years, and the complexity of delivering it dynamically to Web users, have resulted in the increased popularity of programming languages designed specifically for delivery of Web content. The PHP Hypertext Preprocessor is one of the most widely used languages in this field, found on more than 16 million Web sites (

Python vs. PHP: Choosing your next project's language

PHP is similar to Microsoft Active Server Pages, Java Servlets and Cold Fusion Module but is commonly held to be much easier to program (or 'script') with, much faster than its competitors and, best of all, it is free to use and distribute.

What is a Hypertext Preprocessor?

These programs read and translate instructions embedded in a Web page before the Web server sends it to your browser (JavaScript could be said to be a Hypertext Postprocessor in as much as it is interpreted after the delivery of the page).

It might be easier to understand this in an example: is powered by PHP and when you open in your Web browser, the Web server running the site asks PHP to translate any embedded instructions in the Web page. Within the page itself, PHP is "instructed to: check if the person requesting the page is logged in; generate a list of HelpScreen categories; locate the most recent questions on the site; generate the HelpScreen poll information, and much more. It is testament to the design of PHP that all this takes only a split second.

Should I use PHP?

PHP is ideal if you want your Web pages to be generated dynamically. That is, if you are finding it too laborious to update static Web pages constantly (consider how time-consuming it would be to rebuild the Web site every time someone asked a question!) or if your Web page needs to get information from other places, such as the system clock to display the current time, or a file or database system to display an address book.

How do I use PHP?

In order to use PHP you will need access to a Web server which runs the PHP Preprocessor. If your Web site is hosted by your ISP or a Web hosting company, you should enquire if they offer access to PHP; many do. If your Web site runs on your own server, you can install PHP on it yourself. If you are going to do this, follow these installation instructions:

Linux/UNIX users should unpack the source archive php-4.0.5.tar.gz. For information on installation, see the INSTALL file in the archive.

Windows users should unpack the Windows' binary release located in Follow the instructions in install.txt for information on how to install PHP for your Web server.

If you don't have a Web server, you can use the Apache distribution. Linux/UNIX users should use apache_1.3.20.tar.gz archive. Installation information is included in the INSTALL file, as in the case of PHP. Windows users need only execute the file apache_1.3.20-win32-no_src-r2.msi. This will launch an install wizard that will guide you through the installation.

Setting up the PHP processor and your Web server is only half the story, however. Writing a PHP 'script' which will be processed by this system involves embedding instructions in a text file with the HTML you want to output. As in the case of an HTML document, this can be done with a standard text editor such as Vi or Pico on Linux/UNIX systems, or Notepad under Windows.

Let's have a look at a simple PHP script:<HTML><BODY> <? echo "Hello World!"; ?><? echo "The time is ".date('D M d H:i:s T Y')."\n"; ?> </BODY> </HTML>Save this file as hello.php and upload it to your PHP-enabled Web server. Requesting this page from your Web server with your browser will give you a page containing 'Hello World!' and a formatted current date. Notice that the PHP instructions are bracketed by <? and ?> tags - this is how the preprocessor knows the difference between HTML and PHP. PHP code (and all HTML) outside these brackets will be ignored and simply sent directly to the Web browser of the person requesting the page.

The two instructions which do the work in our example are 'echo' and 'date'. These functions are built into PHP. The echo function does what its name suggests - it 'echoes' to output the string following it. The second call to the echo function is followed by a string made up of several substrings. Next month we will look at how this works, and why it is useful in PHP.

Meanwhile, the date() function allows us to format the current date and time (see for meanings of the letters passed to the date() function). There are many other built- in PHP functions, all of which are documented in the PHP manual at

Next we will take a close look at strings in PHP as well as exploring the difference between functions and control structures (such as loops) in preparation for our first project: a PHP script which manages an online address book.

Join the PC World newsletter!

Error: Please check your email address.

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Gavin Sherry

PC World
Show Comments

Most Popular Reviews

Latest News Articles


PCW Evaluation Team

Azadeh Williams

HP OfficeJet Pro 8730

A smarter way to print for busy small business owners, combining speedy printing with scanning and copying, making it easier to produce high quality documents and images at a touch of a button.

Andrew Grant

HP OfficeJet Pro 8730

I've had a multifunction printer in the office going on 10 years now. It was a neat bit of kit back in the day -- print, copy, scan, fax -- when printing over WiFi felt a bit like magic. It’s seen better days though and an upgrade’s well overdue. This HP OfficeJet Pro 8730 looks like it ticks all the same boxes: print, copy, scan, and fax. (Really? Does anyone fax anything any more? I guess it's good to know the facility’s there, just in case.) Printing over WiFi is more-or- less standard these days.

Ed Dawson

HP OfficeJet Pro 8730

As a freelance writer who is always on the go, I like my technology to be both efficient and effective so I can do my job well. The HP OfficeJet Pro 8730 Inkjet Printer ticks all the boxes in terms of form factor, performance and user interface.

Michael Hargreaves

Windows 10 for Business / Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Aysha Strobbe

Windows 10 / HP Spectre x360

Ultimately, I think the Windows 10 environment is excellent for me as it caters for so many different uses. The inclusion of the Xbox app is also great for when you need some downtime too!

Mark Escubio

Windows 10 / Lenovo Yoga 910

For me, the Xbox Play Anywhere is a great new feature as it allows you to play your current Xbox games with higher resolutions and better graphics without forking out extra cash for another copy. Although available titles are still scarce, but I’m sure it will grow in time.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?