You are here: Re: Command « All PHP « IT news, forums, messages
Re: Command

Posted by Daniel Ennis on 01/14/08 07:05

Daniel Ennis wrote:
> Fred Atkinson wrote:
>> On Sun, 13 Jan 2008 20:59:03 -0500, Fred Atkinson
>> <fatkinson@mishmash.com> wrote:
>>
>> OK,
>> I think I've got it.
>> I slightly rewrote your script (one line with an if statement)
>> to include a second comparison.
>> Here it is:
>> <?php
>> $dir = './directory';
>> function countfiles($dir = '.')
>> {
>> $count = 0;
>> $dir = rtrim($dir,'/').'/';
>> if(!is_dir($dir)) return false;
>> foreach(new DirectoryIterator($dir) as $file)
>> {
>> if((is_file($dir.$file) && preg_match("/.jpg\z/i",
>> $file))) $count++;
>> }
>> return $count;
>> }
>> echo countfiles();
>> echo " file(s) in this directory."
>> ?>
>>
>> It seems to work just fine. It ignores anything except .jpg
>> files.
>> Regards,
>>
>>
>> Fred
>
> GJ :) Hope what ever your working on comes out well!
>
> And yes, the default PHP5 functions will be faster than old style code,
> as its optimized C++ doing all the tasks you would normally do manually
> in PHP4.
>

And using
if((is_file($dir.$file) && strrchr($fileName, '.') == '.jpg') $count++;


would likely be faster than using regex. Such a simple check doesnt
really need the full power of regex.

--
Daniel Ennis
faNetworks.net - Quality Web Hosting and Ventrilo Services
System Administrator / Web Developer
PHP Developer for 6 years
daniel@fanetworks.net

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация