[thelist] Bad tip on my part

Faust at LeeMarvin.com Faust at LeeMarvin.com
Fri Mar 1 12:08:02 CST 2002


Opps....  Make that.

<tip type="php" author="Faust">

// Here's a function for finding the number of days in Feburary
// with a little test loop.

for ($i = 0; $i <= 11000; $i = $i + mt_rand(1, 100)) {
   echo "daysInFebruary($i) = " . daysInFebruary($i) . "<br>";
}

function daysInFebruary($s) {
// int daysInFebruary(mixed var)
// Returns number of days in February for a valid four digit year, FALSE
otherwise.
   $s = trim($s);
   if (isYear($s) && strlen($s) == 4) {
      return (($s % 4 == 0) &&  ((!($s % 100 == 0)) || ($s % 400 == 0))) ?
29 : 28;
   }
   return false;
}

function isYear($s){
// bool isYear(mixed var)
// Returns TRUE if var is a two for four digit year,
// FALSE otherwise.
   $s = trim($s);
   if (strlen($s) == 2 || strlen($s) == 4) {
      $s = intval($s);
      return ($s > 0 && $s < 10000);
   }
   else {
      return false;
   }
}
</tip>





More information about the thelist mailing list