#45399 [NEW]: sprintf returns wrong string

From: Date: Tue, 01 Jul 2008 10:39:15 +0000
Subject: #45399 [NEW]: sprintf returns wrong string
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-126140@lists.php.net to get a copy of this message
From: hostmaster at mindrabbit dot com Operating system: Fedora Core 8 (x86_64) PHP version: 5.2.6 PHP Bug Type: Strings related Bug description: sprintf returns wrong string Description: ------------ I'm trying to add zeros before string if the length of string is lower than, let's say 8. Function is not checking the given string length, if the length is same than it should return, sprintf() will replace ALL chars with zero (see examples). Reproduce code: --------------- $hex = 'F5F2F4'; return sprintf("%08d", $hex); => Returns 000F5F2F4 like it should be $hex = 'F2F45F2F4'; return sprintf("%08d", $hex); => Returns 00000000, not F2F45F2F4 like it should be Expected result: ---------------- $hex = 'F5F2F4'; return sprintf("%08d", $hex); => Returns 000F5F2F4 like it should be $hex = 'F2F45F2F4'; return sprintf("%08d", $hex); => Returns 00000000, not F2F45F2F4 like it should be Actual result: -------------- $hex = 'F5F2F4'; return sprintf("%08d", $hex); => Returns 000F5F2F4 like it should be $hex = 'F2F45F2F4'; return sprintf("%08d", $hex); => Returns 00000000, not F2F45F2F4 like it should be -- Edit bug report at http://bugs.php.net/?id=45399&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45399&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45399&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45399&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45399&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45399&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45399&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45399&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45399&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45399&r=support Expected behavior: http://bugs.php.net/fix.php?id=45399&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45399&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45399&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45399&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45399&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45399&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45399&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45399&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45399&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45399&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45399&r=mysqlcfg

« previous php.bugs (#126140) next »