[thelist] parsing numbers trap

Winfried Huslik winfried at huslik.de
Fri Jun 15 11:05:00 CDT 2001


Hi,

<tip type="mySQL, PHP">
just reading about Netscape's blooper, here is something to be wary about:

Given a Date field from mySQL like "2001-08-04" for August 4th 2001, 
I used the

function longDate($d) {
     eval(ereg_replace('(#+)-(#+)-(#+)',
          '$d = mktime(0,0,0,\\2,\\3,\\1);', $d));
     return date ("l jS F Y", $d);
}

to print something like "Saturday 4th August 2001",
but this does NOT work correct for Months or Days 08 and 09! Why?

Numbers starting with zero are interpreted by PHP as octal (which go from
00 to 07). 08 and 09 are illegal octal numbers and taken for zero
which shows totally confused dates.

The second line must read:
     eval(ereg_replace('(#+)-0?(#+)-0?(#+)',
to eliminate the leading zeroes.

</tip>


Winfried Huslik

(take a look at my work at www.owad.de)

-- 
Winfried Huslik Tel+49 821 565606 Fax 565001 <http://www.huslikverlag.de>
Huslik Verlag GmbH  *  Unterfeldweg 3  *  86199 Augsburg  *  Germany 
  There is always an easy solution to every human problem: 
  neat, plausible, and wrong.  (H. L. Mencken)





More information about the thelist mailing list