|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 17:00:01 2025 UTC |
I will edit little bit: return sprintf("%08s", $hex); Should return string, not integer....