Specifications
You can use this approach for a variety of purposes. Another good example is retrieving local
weather information and embedding it in your page.
The best use of this approach is to combine information from different sources to add some
value. One good example of this approach can be seen in Philip Greenspun’s infamous script
that produces the Bill Gates Wealth Clock:
http://www.webho.com/WealthClock
This page takes information from two sources. It obtains the current U.S. population from the
U.S. Census Bureau’s site. It looks up the current value of a Microsoft share and combines
these two pieces of information, adds a healthy dose of the author’s opinion, and produces new
information—an estimate of Bill Gates’ current worth.
One side note: If you’re using an outside information source such as this for a commercial pur-
pose, it’s a good idea to check with the source first. There are intellectual property issues to
consider in some cases.
If you’re building a script like this, you might want to pass through some data. For example, if
you’re connecting to an outside URL, you might like to pass some parameters typed in by the
user. If you’re doing this, it’s a good idea to use the url_encode() function. This will take a
string and convert it to the proper format for an URL, for example, transforming spaces into
plus signs. You can call it like this:
$encodedparameter = url_encode($parameter);
Using Network Lookup Functions
PHP offers a set of “lookup” functions that can be used to check information about hostnames,
IP addresses, and mail exchanges. For example, if you were setting up a directory site such as
Yahoo! when new URLs were submitted, you might like to automatically check that the host of
an URL and the contact information for that site are valid. This way, you can save some over-
head further down the track when a reviewer comes to look at a site and finds that it doesn’t
exist, or that the email address isn’t valid.
Listing 17.2 shows the HTML for a submission form for a directory like this.
LISTING 17.2 directory_submit.html—HTML for the Submission Form
<head>
<title>Submit your site</title>
</head>
<body>
<h1>Submit site</h1>
Advanced PHP Techniques
P
ART IV
374
22 7842 CH17 3/6/01 3:39 PM Page 374










