Is it possible to do a zerofill with php?
I have a script that generates a random number. The number of digits vary with each random number.
What I want to do is add zeros to the beginning of the generated number, so that I'll always have six digits.
I know I can use mysql for this, but the number will not be stored in a database.
Thanks. Richard.
If it is just for display purposes, which I am assuming it is...this seemed to work:
$i = 2; $j = 32; echo str_pad($i,6,"0",STR_PAD_LEFT) . "<BR>\n"; echo str_pad($j,6,"0",STR_PAD_LEFT) . "<BR>\n";
Matt Wade codewalkers.com
See sprintf, printf, et cetera, in the manual.