August 2003
Intermediate to advanced
1104 pages
19h 27m
English
The basic function for executing regular expressions is ereg. This function evaluates a string against a regular expression, returning TRUE if the pattern described by the regular expression appears in the string. In this minimal form, you can check that a string conforms to a given pattern. For example, you can ensure that a U.S. postal ZIP code is in the proper form of five digits followed by a dash and four more digits. Listing 22.2 demonstrates this idea; Figure 22.2 shows the output.
<?php /* ** Check a ZIP code ** This script will test a zip code, which ** must be five digits, optionally followed by ** a dash and four digits. */ /* ** if zip submitted evaluate ... |
Read now
Unlock full access