I want to add 0s to a number.
Let's say I have 5, I have to add 4 digits like this:
00005
If I have 17 I have to add 3 digits like this:
00017
Printable View
I want to add 0s to a number.
Let's say I have 5, I have to add 4 digits like this:
00005
If I have 17 I have to add 3 digits like this:
00017
str_pad :)
PHP Code:<?php
$num = 9;
echo str_pad($num, 5, "0", STR_PAD_LEFT);
$num = 17;
echo str_pad($num, 5, "0", STR_PAD_LEFT);
?>
PHP Code:$num = 5;
$zeros = "0000";
echo $zeros.$num;
$num = 17;
$zeros = "000";
echo $zeros.$num;
$r = sprintf('%05d', $number);