note 56024 added to function.checkdate
| From: | . org | Date: | Sun, 21 Aug 2005 04:35:09 +0000 |
| Subject: | note 56024 added to function.checkdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93973@lists.php.net to get a copy of this message | ||
The function of phil@philmo contains a few errors...
I corrected them as far as I found them and tried to improve the code.
<?php
/**
* Checks for a valid date
*
* @param string Date in the format "MM-DD-YYYY"
* @param integer Disallow years more than $yearepsilon from now (in future as well as in past)
* @return array [ month, day, year ]
* @since 1.0
*/
/* fixed:
** - leap years
** - december now is allowed
** - removed unnecessary checking
** if you find any more mistakes, please correct them. :)
*/
function datecheck($date, $yearepsilon=5000) {
if (count($datebits=explode('-'))!=3) return false;
$month = intval($datebits[0]);
$day = intval($datebits[1]);
$year = intval($datebits[2]);
if ((abs($year-date('Y'))>$yearepsilon) || // year outside given range
($month<1) || ($month>12) || ($day<1) ||
(($month==2) && ($day>28+(!($year%4))-(!($year%100))+(!($year%400)))) ||
($day>30+(($m>7)^($m&1)))) return false; // date out of range
return array(
'year' => $year
'month' => $month,
'day' => $day,
);
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.checkdate.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56024
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56024&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56024&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56024&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56024&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56024&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56024&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56024&report=yes
Search -- http://master.php.net/manage/user-notes.php