--- Boaz Yahav <[EMAIL PROTECTED]> wrote:
> wouldn't this just print empty spaces before the number instead of the
> needed Zeros?

Yes, you are correct.

> -----Original Message-----
> From: Martin Towell [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, March 20, 2003 1:11 AM
> To: 'Harry.de'; [EMAIL PROTECTED]
> Subject: RE: [PHP] Zero Fill -> Number Format
> 
> sprintf/printf("%7d", $num)
> 
> -----Original Message-----
> From: Harry.de [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 20, 2003 10:09 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Zero Fill -> Number Format
> 
> How can I put out a Zero Fill for numbers
> The result should be
> 
> $something=26;
> echo $something;
> 
> e.g.
> 0000026

I'm sure there is a better way, but I can add two lines of code between yours
above to accomplish what you want, resulting in this:

$something = 26;
$something = sprintf('%7d', $something);
$something = str_replace(' ', '0', $something);
echo $something;

Chris

=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to