note 103180 deleted from function.checkdate by danbrown

From: Date: Wed, 30 Mar 2011 14:03:24 +0000
Subject: note 103180 deleted from function.checkdate by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178339@lists.php.net to get a copy of this message
Note Submitter: phil at lavin dot me dot uk ---- Holy not-testing... Took me 5 mins to work out the bugs in the code. Would have been easier to re-write it. Here's the corrected version of gman's code: <?php function is_leap($year = null) { if (strpos($year, '+') === 0) { $chunk = explode('+', $year); return checkdate(2, 29, date('Y') + $chunk[1]); } else { return checkdate(2, 29, ($year == null) ? date('Y') : $year); } } //Usage if (is_leap()) { echo "Current Year is a leap year"; } if (is_leap(1992)) { echo "1992 was a leap year"; } if (is_leap('+4')) { echo "In four years it will be a leap year"; } ?>

« previous php.notes (#178339) next »