Re: Easy Way.
| From: | Chris Hayes | Date: | Sun, 09 Mar 2003 21:28:26 +0000 |
| Subject: | Re: Easy Way. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138886@lists.php.net to get a copy of this message | ||
At 22:23 9-3-2003, you wrote:
You're looking for the str_pad function. http://www.php.net/str_pad $i = 3; $i = str_pad($i, 5, '0', STR_PAD_LEFT); echo $i; // outputs '00003' Just keep in mind that it won't help you if your input is greater than 5 to begin with, you'll have to check that seperately.You can also have a look at http://nl.php.net/manual/en/function.sprintf.php Example 5. sprintf(): zero-padded integers $isodate = sprintf("%04d-%02d-%02d", $year, $month, $day); if it is only for output, have a look at http://nl.php.net/manual/en/function.printf.php