Datasheet
</head>
<body>
<h1>Question</h1>
<p>
What is the answer to the sum <code>2 + 2</code>?
</p>
<h2>Answer</h2>
<?php
echo 2 + 2 ;
?>
</body>
</html>
I’ll be making a lot of use of PHP in the chapters that follow, and some experience of PHP is assumed
throughout most of this book. If you need to brush up on your PHP skills, the main PHP web site at
http://www.php.net/ is always a good place to start. There you will find the PHP documentation
and tutorials.
Like PHP, Perl is a scripting language, and it has a very long history. Created by Larry Wall in the mid
1980s, it has become one of the most widely used tools around. System administrators refer to it as the
“duct tape of the Internet”: its versatility and almost ubiquitous availability allow it to be easily applied
in most situations.
Perl is available for a large variety of computing platforms, and is supported by a comprehensive library
of add-on modules available from CPAN — the Comprehensive Perl Archive Network — which can be found
at
http://cpan.perl.org/.
Regular Expressions
A regular expression is a string that defines a pattern that is used to match one or more strings, and is typi-
cally used to search for specific patterns within a larger string. The easiest way to understand what this
means is by seeing an example or two — let’s look at a few examples of typical regular expressions.
Many types of regular expressions exist — in this book, I use only
Perl-style regular expressions.
Here’s a very simple regular expression:
/Flickr/
The regular expression, often shortened to regexp, is delimited by forward slashes. Within the slashes is
the pattern to be matched. Here the pattern is very simple— it’s the word
Flickr. This pattern will
match any string that contains the text
Flickr. The following are all strings that match the pattern.
Flickr Mashups
The Flickr web site
I like Flickr
Most regular expressions aren’t that straightforward, however. Many special characters can be used
within a regexp pattern to perform more complex matches. For example, the caret character (
^) is used
to match the start of a string, and the dollar sign (
$) matches the end of a string. Look at this regexp:
/^Flickr/
17
Chapter 1: Rewriting the Web
05_097748 ch01.qxp 12/14/06 5:53 PM Page 17










