Created
April 4, 2011 14:38
-
-
Save joshuabaker/901745 to your computer and use it in GitHub Desktop.
Pad a string or zero fill a number using PHP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$number = 5; | |
echo sprintf('%02s', $number); // 05 | |
echo sprintf('%03s', $number); // 005 | |
echo sprintf('%02s', 453); // 453 | |
// sprintf is faster than str_pad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment