note 90345 modified in function.checkdate by danbrown
| From: | danbrown@php.net | Date: | Fri, 17 Apr 2009 15:57:28 +0000 |
| Subject: | note 90345 modified in function.checkdate by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153443@lists.php.net to get a copy of this message | ||
[NOTE BY danbrown AT php DOT net: The author's purpose for this function is to determine
whether or not a given string $str is a date using a static algorithm.]
<?php
function is_date( $str )
{
$stamp = strtotime( $str );
if (!is_numeric($stamp))
{
return FALSE;
}
$month = date( 'm', $stamp );
$day = date( 'd', $stamp );
$year = date( 'Y', $stamp );
if (checkdate($month, $day, $year))
{
return TRUE;
}
return FALSE;
}
?>
--was--
function is_date( $str )
{
$stamp = strtotime( $str );
if (!is_numeric($stamp))
{
return FALSE;
}
$month = date( 'm', $stamp );
$day = date( 'd', $stamp );
$year = date( 'Y', $stamp );
if (checkdate($month, $day, $year))
{
return TRUE;
}
return FALSE;
}
http://php.net/manual/en/function.checkdate.php