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?
zerofill
Moderator: General Moderators
-
chris12295
- Forum Contributor
- Posts: 113
- Joined: Sun Jun 09, 2002 10:28 pm
- Location: USA
- Contact:
Not as integers. Prepend a "0" as a string
Note: $num is a string, not an integer.
Code: Select all
<?php
$bla=615;
$num="0".$bla;
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can use sprintf():
Mac
Code: Select all
<?php
$test = 93;
$test_padded = sprintf('%04d', $test);
echo $test_padded;
?>