printf
formats have a zero-padding option:
printf("%05d", $number);
Frage
In PHP, I need to display a big 5 digit, graphical counter from a number fetched from a database. Examples:
What's the easiest way to achieve this?
Lösung 3
printf
formats have a zero-padding option:
printf("%05d", $number);
Andere Tipps
You could use str_pad
:
$output = str_pad ($input, 5, '0', STR_PAD_LEFT);
The versatile printf
or sprintf
for the value 1 as 00001:
printf('%05d', 1);