Page 1 of 1

zerofill

Posted: Thu May 15, 2003 6:11 pm
by chris12295
i want this

$num = 615;

to change to this

$num = 0615;

the numbers come from an array so i dont know how long they are, i just know they are no more than 4 digits.

is there any way to zerofill 1-3 digit numbers?

Posted: Thu May 15, 2003 6:32 pm
by patrikG
Not as integers. Prepend a "0" as a string

Code: Select all

<?php
$bla=615;
$num="0".$bla;
?>
Note: $num is a string, not an integer.

Posted: Fri May 16, 2003 2:34 am
by twigletmac
You can use sprintf():

Code: Select all

<?php
$test = 93;
$test_padded = sprintf('%04d', $test);
echo $test_padded;
?>
Mac