[thelist] [PHP] Add a leading zero to a single digit integer

Matt Warden mwarden at gmail.com
Wed Nov 24 21:32:09 CST 2004


Tim,

On Thu, 25 Nov 2004 13:42:13 +1030, Tim Burgan <email at timburgan.com> wrote:
> Hi,
> 
> How can I add a leading zero to an integer IF its length it one digit?
> 
> eg.  8 -> 08
>      9 -> 09
>     10 -> 10
>     11 -> 11
> 
> Is there a PHP function to do this? Or is there a function that I can
> use to return the length of digits in the integer - strlen()?

http://us2.php.net/manual/en/function.str-pad.php

Once you get into padding with zeros, you're formatting and therefore
you need to treat the value as a string, not an integer.


-- 
Matt Warden
Miami University
Oxford, OH
http://mattwarden.com


This email proudly and graciously contributes to entropy.


More information about the thelist mailing list