RE: [PHP] Zero Fill -> Number Format
oops, sorry - try this instead sprintf/printf("%07d", $num) -Original Message- From: Boaz Yahav [mailto:[EMAIL PROTECTED] Sent: Friday, March 21, 2003 8:23 AM To: Martin Towell; Harry.de; [EMAIL PROTECTED] Subject: RE: [PHP] Zero Fill -> Number Format wouldn't this just print empty spaces before the number instead of the needed Zeros? -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. 026 I didn't found a solution with number format. Is there any other way? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Zero Fill -> Number Format
> $something = 26; > $something = sprintf('%7d', $something); > $something = str_replace(' ', '0', $something); > echo $something; This is a bit more direct: $something = 26; echo str_pad($something, 7, '0', STR_PAD_LEFT); 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
RE: [PHP] Zero Fill -> Number Format
--- 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. > 026 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
RE: [PHP] Zero Fill -> Number Format
wouldn't this just print empty spaces before the number instead of the needed Zeros? -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. 026 I didn't found a solution with number format. Is there any other way? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Zero Fill -> Number Format
Just an observer, but I love how you each had a different way of accomplishing this task! ;-) And Mike, looks like you have some re-writing to do now that Martin and Kevin showed you a WAY simpler (and faster) way to accomplish what you did. LOL. http://daevid.com > -Original Message- > From: Martin Towell [mailto:[EMAIL PROTECTED] > > sprintf/printf("%7d", $num) -Original Message- >From: Kevin Waterson [mailto:[EMAIL PROTECTED] > >print str_pad($something, 7, "0", STR_PAD_LEFT); -Original Message- From: Mike Brum [mailto:[EMAIL PROTECTED] This is what I did for a dynamic zero-fill for renaming batches of files: // Get "Zero Padding" For New Image Names $zero_padding = strlen(count($image_array)); foreach($image_array as $temp){ $n++; $n_length = strlen($n); for($i = 0; $i < ($zero_padding - $n_length); $i++){ $n = "0" . $n; } $new_name = $image_inbox . "/" . $newName . "-" . $n . ".jpg"; rename("$image_inbox/$temp", $new_name); } I'm not sure if this will be applicable to your situation, but it works perfectly for me since it will zero-fill for any length of numbers and pad the shorter numbers appropriately. > -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. > 026 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Zero Fill -> Number Format
This one time, at band camp, "Harry.de" <[EMAIL PROTECTED]> wrote: > How can I put out a Zero Fill for numbers > The result should be > > $something=26; print str_pad($something, 7, "0", STR_PAD_LEFT); Kevin __ (_ \ _) ) | / / _ ) / _ | / ___) / _ ) | | ( (/ / ( ( | |( (___ ( (/ / |_| \) \_||_| \) \) Kevin Waterson Port Macquarie, Australia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Zero Fill -> Number Format
This is what I did for a dynamic zero-fill for renaming batches of files: // Get "Zero Padding" For New Image Names $zero_padding = strlen(count($image_array)); foreach($image_array as $temp){ $n++; $n_length = strlen($n); for($i = 0; $i < ($zero_padding - $n_length); $i++){ $n = "0" . $n; } $new_name = $image_inbox . "/" . $newName . "-" . $n . ".jpg"; rename("$image_inbox/$temp", $new_name); } I'm not sure if this will be applicable to your situation, but it works perfectly for me since it will zero-fill for any length of numbers and pad the shorter numbers appropriately. -M -Original Message- From: Harry.de [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 19, 2003 6:09 PM 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. 026 I didn't found a solution with number format. Is there any other way? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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. 026 I didn't found a solution with number format. Is there any other way? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php