Introducing PHP
PHP is a scripting language that is designed to be embedded into the HTML markup used for web pages; it can be used for other purposes, but that’s outside the scope of our discussions. It works on almost all Unix platforms—including Linux and Mac OS X—and with Windows 32-bit environments, such as Windows 2000, XP, and Vista. Web pages that contain PHP scripts are preprocessed by the PHP scripting engine, and the source code is replaced with the output of the script. Indeed, the acronym PHP obliquely suggests just that—PHP: Hypertext Preprocessor.
PHP is extremely popular for several reasons: it’s easy to include PHP scripts in HTML documents, PHP is free in a monetary and open source sense, it has a large number of powerful but easy-to-use function libraries, and it shares syntax with C or Perl-like languages. PHP is also widely supported; there are a very large number of books, web sites, and add-on products available. You’ll find that moving from simple examples to advanced material is made easy by this wide-ranging support.
Example 13-1 shows simple PHP script embedded in an HTML document:
Example 13-1. PHP Script to say “Hello, world!”
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <title>Hello, world</title> </head> <body> <?php echo "Hello, world"; ?> </body> </html>
When preprocessed by the PHP scripting engine, the short (and not very useful) script:
<?php echo "Hello, world"; ?>
is replaced ...
Get Learning MySQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.