Validating a Date


 checkdate(2, 29, 2000) 


When you get a datefor example, from the user using an HTML formthis data must be validated. This includes checking whether the month exists and if the month has enough days. If it's February, you might also want to find out whether it is a leap year.

Validating Date Information (checkdate.php)
 <?php   echo '2000 was ' .     (checkdate(2, 29, 2000) ? 'a' : 'no') .     ' leap year.<br />';   echo '2100 will be ' .     (checkdate(2, 29, 2100) ? 'a' : 'no') .     ' leap year.'; ?> 

But PHP would not be PHP if you really had to do this on your own. The function checkdate() validates a date; you provide the month, the day, and the year as parameters.




PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net