note 92604 deleted from function.checkdate by thiago

From: Date: Fri, 31 Jul 2009 12:59:46 +0000
Subject: note 92604 deleted from function.checkdate by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158954@lists.php.net to get a copy of this message
Note Submitter: aldo at mschat dot net ---- @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.'; ?>

« previous php.notes (#158954) next »