note 74588 deleted from function.readdir by nlopess
| From: | nlopess@php.net | Date: | Tue, 01 May 2007 13:37:04 +0000 |
| Subject: | note 74588 deleted from function.readdir by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126035@lists.php.net to get a copy of this message | ||
Note Submitter: Paul Gregg
----
I just released an updated version of preg_find() [which has been linked from the glob() man page
for years] - this function should provide most of what you want back from reading files,
directories, different sorting methods, recursion, and perhaps most powerful of all the ability to
pattern match with a PCRE regex.
It would be unfair to spam the note with a huge paste, so you can Download preg_find here: http://www.pgregg.com/projects/php/preg_find/preg_find.php.txt
or if you prefer colourful .phps format: http://www.pgregg.com/projects/php/preg_find/preg_find.phps
I wrote several examples on how to use it on my blog at: http://www.pgregg.com/forums/viewtopic.php?tid=73
But briefly here:
simple glob() type replacement:
$files = preg_find('/./', $dir);
recursive?
$files = preg_find('/./', $dir, PREG_FIND_RECURSIVE);
pattern match? find all .php files:
$files = preg_find('/\.php$/D', $dir, PREG_FIND_RECURSIVE);
sorted alphabetically?
$files = preg_find('/\.php$/D', $dir, PREG_FIND_RECURSIVE|PREG_FIND_SORTKEYS);
sorted in by filesize, in descending order?
$files = preg_find('/./', $dir,
PREG_FIND_RECURSIVE|PREG_FIND_RETURNASSOC |PREG_FIND_SORTFILESIZE|PREG_FIND_SORTDESC);
$files=array_keys($files);
sorted by date modified?
$files = preg_find('/./', $dir,
PREG_FIND_RECURSIVE|PREG_FIND_RETURNASSOC |PREG_FIND_SORTMODIFIED);
$files=array_keys($files);
and much more.
Enjoy.