RE: [PHP] Insert leading zeros
| From: | Matt Palermo | Date: | Wed, 16 Jul 2003 00:48:35 +0000 |
| Subject: | RE: [PHP] Insert leading zeros | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155351@lists.php.net to get a copy of this message | ||
Thanks a lot. It works like a charm!
-----Original Message-----
From: Curt Zirzow [mailto:curt@zirzow.dyndns.org]
Sent: Tuesday, July 15, 2003 8:45 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Insert leading zeros
Matt Palermo <mpalermo@vt.edu> wrote:
> I have a string of digits that looks like something like these: 0025,
> 1234, 0001, 1003, and so on. They are all 4 digits in length. Then
> when I increment one of them by 1, I want to still have 4 digits for
the
> value (it should insert the leading zeros if needed). Is there any
type
> of function that will force the incremented value to be exactly 4
digits
> no matter what number it increments? Please let me know if there is a
> function that will insert these leading zeros or truncate it to 4
digits
> if necessary. Thanks.
$var = sprintf("%04d", $var+1);
Curt
--
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php