Page 68 - Beginning PHP 5.3
P. 68

Part I: Getting Up and Running with  PHP
                   To write multi - line comments, start the comment with a slash followed by an asterisk (/*) and end the
                 comment with an asterisk followed by a slash (*/), as follows:

                    /*
                      This code displays the
                      current time in a nice,
                      easy-to-read format.

                    */
                   So you might comment the PHP code in the hello_with_time.php script like this:

                        < ?php
                    // Get the current time in a readable format
                    $currentTime = date( “g:i:s a” );

                    // Display greeting and time to the visitor
                    echo “Hello, world! The current time is $currentTime”;
                    ? >



                  Summary

                   After reading this chapter you ’ ve moved from PHP theory to practice. To start with, you studied how to
                 set up a PHP Web server on your own computer  —  whether it ’ s a Linux, Windows, or Mac machine  —
                   and to write a few simple PHP scripts. Along the way, you learned:

                   ❑       How to install the Apache, PHP, and MySQL packages on Ubuntu Linux
                   ❑       The easy way to install Apache, PHP, and MySQL on Windows and Mac OS X: Use WampServer
                       and MAMP
                   ❑       Techniques for testing that your Web server and PHP engine are installed correctly
                   ❑       Some alternative ways to run PHP, including using PHP with IIS, compiling PHP from scratch,
                       and running PHP scripts on your Web hosting account
                   ❑       Writing a simple PHP script, and extending the script by embedding PHP within HTML and
                       adding dynamic elements
                   ❑       Improving the readability of your PHP scripts by adding comments to your code

                   You ’ re now ready to take the next step and explore the PHP language from the ground up. You ’ ll be
                 doing this in the next chapter. Meanwhile, try the following simple exercise to test your knowledge so far.

                   You can find the solutions to all the exercises in this book in Appendix A.



                  Exercise

                      1.     Enhance the hello_with_time.php script to display the current date as well as the time.
                       Comment your code for readability. (Hint: With the date() function, you can use M to display
                       the month name, j to display the day of the month, and Y to display the year.)


              30





                                                                                                      9/21/09   8:50:27 AM
          c02.indd   30
          c02.indd   30                                                                               9/21/09   8:50:27 AM
   63   64   65   66   67   68   69   70   71   72   73