#45399 [Opn]: sprintf returns wrong string

From: Date: Tue, 01 Jul 2008 10:41:59 +0000
Subject: #45399 [Opn]: sprintf returns wrong string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-126141@lists.php.net to get a copy of this message
ID: 45399 User updated by: hostmaster at mindrabbit dot com Reported By: hostmaster at mindrabbit dot com Status: Open Bug Type: Strings related Operating System: Fedora Core 8 (x86_64) PHP Version: 5.2.6 New Comment: I will edit little bit: return sprintf("%08s", $hex); Should return string, not integer.... Previous Comments: ------------------------------------------------------------------------ [2008-07-01 10:39:15] hostmaster at mindrabbit dot com 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 this bug report at http://bugs.php.net/?id=45399&edit=1

« previous php.bugs (#126141) next »