note 30065 added to function.number-format
| From: | gal_chen at hotmail dot com | Date: | Wed, 05 Mar 2003 16:58:53 +0000 |
| Subject: | note 30065 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44885@lists.php.net to get a copy of this message | ||
a better way to add a leadin zero
$i = 15;
while (strlen($i) < 3)
$i = 0 . $i;
can put it in a function
or use a recoursive function
function inc_length ($num,$length) {
// $num is the number and $lenght is wanted length
if (strlen($num) >= $length) {
return $num;
} else {
return inc_length (0 . $num , $length);
}
}
echo inc_length(23,5); will echo "00023"
--
http://www.php.net/manual/en/function.number-format.php
http://master.php.net/manage/user-notes.php?action=edit+30065
http://master.php.net/manage/user-notes.php?action=delete+30065
http://master.php.net/manage/user-notes.php?action=reject+30065