Re: Insert leading zeros

From: Date: Wed, 16 Jul 2003 00:45:20 +0000
Subject: Re: Insert leading zeros
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-155350@lists.php.net to get a copy of this message
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 --

« previous php.general (#155350) next »