Page 521 - Beginning PHP 5.3
P. 521

Chapter 16: PHP and the Outside World































                                Figure 16-1


                       Try It Out     Calculate Your Age in Days
                         You can use your newfound knowledge of PHP’s date handling functions to write a script that
                         calculates the user’s age in days. The script presents a form asking the user to input his or her date of
                         birth, then calculates the difference (in days) between this date and the current date.
                         Save the following script as days_old.php in your document root folder. Because the script uses the
                         HTML_QuickForm and HTML_QuickForm_Renderer_Tableless PEAR packages, make sure you
                         install these as well. You can find detailed information on installing these packages in the previous
                         chapter.

                             <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
                               “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
                             <html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
                               <head>
                                 <title>How many days old are you?</title>
                                 <link rel=”stylesheet” type=”text/css” href=”common.css” />
                                 <style type=”text/css”>
                                   .error { background: #d33; color: white; padding: 0.2em; margin:
                             0.2em 0 0.2em 0; font-size: 0.9em; }
                                   fieldset { border: none; }
                                   ol {list-style-type: none; }
                                   input, select, textarea { float: none; margin: 1em 0 0 0; width:
                             auto; }
                                   div.element { float: right; width: 57%; }
                                   div.element label { display: inline; float: none; }
                                   select { margin-right: 0.5em; }

                                                                                                         483





                                                                                                      9/21/09   9:15:31 AM
          c16.indd   483
          c16.indd   483                                                                              9/21/09   9:15:31 AM
   516   517   518   519   520   521   522   523   524   525   526