Page 605 - Beginning PHP 5.3
P. 605
Chapter 18: String Matching with Regular Expressions
$productCodes = array(
“SW” => “SuperWidget”,
“MW” => “MegaWidget”,
“WW” => “WonderWidget”
);
return $productCodes[$matches[1]] . “ model #” . $matches[2];
}
?>
</body>
</html>
Run the script by opening its URL in your Web browser. Fill in the form with your email address and
phone number, along with some product codes in the prescribed format, as shown in Figure 18-2.
Click Send Order to process the form. Notice how the thank-you page (Figure 18-3) expands the
product codes you entered into more meaningful product names.
Try returning to the form and entering email addresses and phone numbers in different formats, then
resending the form. You should find that, although the script is quite tolerant of different formats, it
still rejects any email addresses or phone numbers that don’t obey the standard formatting rules.
Figure 18-2
567
9/21/09 6:18:02 PM
c18.indd 567
c18.indd 567 9/21/09 6:18:02 PM