RE: [PHP] Zero Fill -> Number Format
| From: | Daevid Vincent | Date: | Thu, 20 Mar 2003 20:16:25 +0000 |
| Subject: | RE: [PHP] Zero Fill -> Number Format | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-140470@lists.php.net to get a copy of this message | ||
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:martin.towell@world.net]
>
> sprintf/printf("%7d", $num)
-----Original Message-----
>From: Kevin Waterson [mailto:kevin@oceania.net]
>
>print str_pad($something, 7, "0", STR_PAD_LEFT);
-----Original Message-----
From: Mike Brum [mailto:php@crazyted.com]
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: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