. is_object, which determines if the variable stores (Web hosting company)

. is_object, which determines if the variable stores an object (remember this one when you try object-oriented coding using PHP; it is very useful) These functions are all documented in the PHP manual at www.php.net/variables. In this instance, the use of is_numeric allows you to make sure that the user has entered a numeric value. $movie_rating = trim($_POST[ movie_rating ]); if (!is_numeric($movie_rating)) { $error .= Please+enter+a+numeric+rating+%21%0D%0A ; } else { if ($movie_rating < 0 || $movie_rating > 10) { $error .= Please+enter+a+rating+ . between+0+and+10%21%0D%0A ; } } The code first cleans up the value of leading and trailing spaces with the trim() function (always try to be prepared for typos and mishaps) and then tests to see if the value is numeric. If it s not, the error message queue is fed; if it is, the code tests the value to see if it is between 0 and 10. If the value is not between 0 and 10, it adds an error message to the error message queue. The date validation is almost as simple to understand, if you know about regular expressions. Here s a closer look at it: $movie_release = trim($_POST[ movie_release ]); if (!ereg( ([0-9]{2})-([0-9]{2})-([0-9]{4}) , $movie_release, $reldatepart) || empty($movie_release)) { $error .= Please+enter+a+date+ . with+the+dd-mm-yyyy+format%21%0D%0A ; } else { $movie_release = @mktime(0, 0, 0, $reldatepart[ 2 ], $reldatepart[ 1 ], $reldatepart[ 3 ]); if ($movie_release == -1 ) { $error .= Please+enter+a+real+date+ . with+the+dd-mm-yyyy+format%21%0D%0A ; } } As you saw in this chapter s first exercise, you use the trim() function to clear all leading and trailing spaces in the received string to make sure your user entered something other than just a space. You can find the string manipulation functions at the PHP Web site at www.php.net/strings. You can find trim() and some other very useful functions there. The next statement contains two conditions. The first condition tests for a regular expression match. The regular expression is ([0-9]{2})-([0-9]{2})-([0-9]{4}) . What does this do? [0-9]{2} specifies that you want to check for numbers between 0 and 9 with two occurrences. For example, 02 will 248 Chapter 8
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Leave a Reply