Re: [PHP] counting with leading zeros



On Wed, 2007-09-26 at 21:56 -0700, Jim Lucas wrote:

Now, if you plan to delete any images in the list, this will not work.

But if you don't expect to delete any images in the list and always want
the ($total_images + 1), then follow along.

<?php

function getNextImage($path, $prefix) {
$filelist = glob("${path}${prefix}*") or return '01';
return str_pad(((int)count($filelist)+1), 2, '0', STR_PAD_LEFT);
}

?>

Nice :)

Cheers,
Rob.
--
............................................................
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
............................................................
.


Quantcast