php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45399 sprintf returns wrong string
Submitted: 2008-07-01 10:39 UTC Modified: 2008-07-01 10:46 UTC
From: hostmaster at mindrabbit dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 5.2.6 OS: Fedora Core 8 (x86_64)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hostmaster at mindrabbit dot com
New email:
PHP Version: OS:

 

 [2008-07-01 10:39 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-01 10:41 UTC] hostmaster at mindrabbit dot com
I will edit little bit:

return sprintf("%08s", $hex);

Should return string, not integer....
 [2008-07-01 10:46 UTC] hostmaster at mindrabbit dot com
This problem get fixed when we reboot our server. Somehow the server didn't work properly overall.

This is not a bug, whis was server error.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jan 16 04:01:23 2021 UTC