Databases Reference
In-Depth Information
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 topics, 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 with its output:
Hello, world
The text before and after the script is HTML; the first three lines define that HTML
version 4 is being used. Any number of PHP scripts can be embedded in an HTML
document, as long as each PHP script is surrounded by the begin tag <?php and the end
tag ?> . Other tags can also be used to delimit PHP scripts, but the tags we use are the
most common and reliable.
One of the best language features of PHP is how it decodes user data and automatically
initializes variables. Consider a sample script stored in the file printuser.php :
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<title>Saying hello</title>
</head>
 
Search WWH ::




Custom Search