note 92604 added to function.checkdate
| From: | aldo at mschat dot net | Date: | Fri, 31 Jul 2009 07:31:24 +0000 |
| Subject: | note 92604 added to function.checkdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158939@lists.php.net to get a copy of this message | ||
@gman at gmail dot com
Your function won't work properly, nor do your examples. But here is a fix:
<?php
function is_leap($year = null)
{
if($year[0] == '+')
return checkdate(2, 29, date('Y') + (int)(substr($year, 1, strlen($year))));
else
return checkdate(2, 29, ($year == null) ? date('Y') : (int)$year);
}
# Examples
echo 'Current year is', is_leap() ? ' ' : ' not ', 'a leap
year.<br />
1992 was', is_leap(1992) ? ' ' : ' not ', 'a leap year.<br />
In four years it will', is_leap('+4') ? ' ' : ' not ', 'be a
leap year.';
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.214.127.218
----
Manual Page -- http://www.php.net/manual/en/function.checkdate.php
Edit -- https://master.php.net/note/edit/92604
Del: integrated -- https://master.php.net/note/delete/92604/integrated
Del: useless -- https://master.php.net/note/delete/92604/useless
Del: bad code -- https://master.php.net/note/delete/92604/bad+code
Del: spam -- https://master.php.net/note/delete/92604/spam
Del: non-english -- https://master.php.net/note/delete/92604/non-english
Del: in docs -- https://master.php.net/note/delete/92604/in+docs
Del: other reasons-- https://master.php.net/note/delete/92604
Reject -- https://master.php.net/note/reject/92604
Search -- https://master.php.net/manage/user-notes.php