RE: [PHP] Zero Fill -> Number Format

From: Date: Thu, 20 Mar 2003 21:31:38 +0000
Subject: RE: [PHP] Zero Fill -> Number Format
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-140486@lists.php.net to get a copy of this message
--- Boaz Yahav <berber@netvision.net.il> 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:martin.towell@world.net] > Sent: Thursday, March 20, 2003 1:11 AM > To: 'Harry.de'; php-general@lists.php.net > Subject: RE: [PHP] Zero Fill -> Number Format > > sprintf/printf("%7d", $num) > > -----Original Message----- > From: Harry.de [mailto:harald.mohring@gmx.de] > Sent: Thursday, March 20, 2003 10:09 AM > To: php-general@lists.php.net > 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/

« previous php.general (#140486) next »