Re: PHP 4.0 Bug #7705 Updated: sscanf does not zero pad decimal

From: Date: Thu, 09 Nov 2000 02:07:32 +0000
Subject: Re: PHP 4.0 Bug #7705 Updated: sscanf does not zero pad decimal
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-37491@lists.php.net to get a copy of this message
My apologies. I had posted this to the php.general newsgroup with no response... Jeff Bug Database wrote: > ID: 7705 > Updated by: derick > Reported By: jccann@home.com > Status: Closed > Bug Type: *General Issues > Assigned To: > Comments: > > This is not a bug, you parsed the day with a %02d, zo the value is interpreted as an number, if > you'd used: > sscanf( $Date, "%02s/%02s/%4d", &$DateMM, &$DateDD, &$DateYYYY ); it > would be fine (because then it's parsed as a string). > > Previous Comments: > --------------------------------------------------------------------------- > > [2000-11-08 20:31:55] jccann@home.com > <?php > $Date = "06/15/2003"; > sscanf( $Date, "%02d/%02d/%4d", &$DateMM, &$DateDD, &$DateYYYY ); > print "date: $Date<br>"; > print "MM: $DateMM<br>"; > print "DD: $DateDD<br>"; > print "YYYY: $DateYYYY<br>" > ?> > > produces this output: > > Date: 06/15/2003 > MM: 6 > DD: 15 > YYYY: 2003 > > Notice that for $DateMM, I specified '%02d", yet the parsed month is '6' > and not '06'. > > According to Example 1 in the PHP manual for sprintf > (http://www.php.net/manual/html/function.sprintf.html) the correct format for zero padded > integers is: > > sprintf ("%04d-%02d-%02d", $year, $month, $day); > > --------------------------------------------------------------------------- > > Full Bug description available at: http://bugs.php.net/?id=7705 -- jccann [at] home [dot] com

« previous php.dev (#37491) next »