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

Mark Kennedy mark at eurogamer.net
Thu Nov 25 04:59:54 CST 2004


I know you have a solution now, but I thought it was worth mentioning 
that http://uk2.php.net/sprintf is incredibly useful for string and 
number formatting.

You could achieve what you wanted with

$str_num = sprintf( "%02d", $num );


Mark


Tim Burgan wrote:
> Thanks for taking the time to reply Ken and Matt,
> 
> I've decided implement a solution close what was suggested by using 
> using the substr() function.
> 
> Thanks again,
> 
> Tim
> 


More information about the thelist mailing list