COPY PASTE desde el manual de php.net
Código PHP:
Here is a simple function to convert numbers into strings like this:
0 => 0000
1 => 0001
20 => 0020
432 => 0432
<?php
function number_pad($number,$n) {
return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
}
?>
$n indicates how many characters you want.