Page 1 of 1

two digits?

Posted: Thu Apr 08, 2004 2:07 pm
by cto1mac
Ok, here is what I am trying:

for($i = 1; $i <= 100; $i++) {
$var .= dechex($i);
}
print $var;

what it outputs is correct but I want is
00 instead of 0
01 instead of 1
....
and so forth how can I force the extra digit?

Thanks

Posted: Thu Apr 08, 2004 2:23 pm
by pickle

Code: Select all

str_pad($var,2,"0",STR_PAD_LEFT);
PHP Manual: [php_man]str_pad[/php_man]

Posted: Thu Apr 08, 2004 2:24 pm
by feyd

Code: Select all

printf("%02d",$value);
or

Code: Select all

sprintf("%02d",$value);

Posted: Thu Apr 08, 2004 2:25 pm
by feyd
hehe.. sometimes there are far too many ways to do the same thing.. ;)