Page 606 - Beginning PHP 5.3
P. 606

Part III: Using PHP in Practice

























                         Figure 18-3

                How It Works
                This script follows the standard “form processor” format that you’ve seen many times before in the
                book. displayForm() is called to display the form markup, which in this case consists of fields for
                email address, phone number, and a list of product codes.

                    processForm()  carries out two broad tasks: first, it uses regular expressions to validate the entered
                email address and phone number, and second, it uses more regular expressions to split the entered
                product list into separate product codes and then convert those codes to human - readable form.
                  After creating an array to store the error messages, the function defines a string to hold the regular
                expression to validate an email address:
                      $emailAddressPattern = “/
                        ^                     # Start of string

                        \w+((-|\.)\w+)*       # Some word characters optionally separated by - or
                                              # .

                        \@

                        [A-Za-z\d]+           # Domain name: some alphanumeric characters
                        ((-|\.)[A-Za-z\d]+)*  # followed 0 or more times by (- or . and more
                                              # alphanums)
                        \.[A-Za-z\d]+         # followed by a final dot and some alphanumerics

                        $                     # End of string
                        /x”;








              568





                                                                                                      9/21/09   6:18:03 PM
          c18.indd   568
          c18.indd   568                                                                              9/21/09   6:18:03 PM
   601   602   603   604   605   606   607   608   609   610   611