[nycphp-talk] PHP addition and leading zeros
agfische at email.smith.edu
Wed Jan 31 09:04:40 EST 2007
sprintf() did the trick nicely, thanks Ken.
On Jan 30, 2007, at 11:32 PM, Ken Robinson wrote:
> At 11:23 PM 1/30/2007, Aaron Fischer wrote:
>> I am retrieving a four digit value from a mysql db. It is an
>> unsigned zerofill field so there are leading zeros.
>> I add 0001 to the value. However, I find that I lose my leading
>> zeros, which I want to keep. I also tried incrementing the value but
>> that produces the same result.
> Use the sprintf() function, <http://www.php.net/sprintf>, to put
> the leading zeros back into the string:
> $num = 1;
> $num_leading_zeros = sprintf("%04d",$num);
> echo $num . ' ----- ' . $num_leading_zeros;
More information about the talk