note 74588 added to function.readdir
| From: | PaulGregg at osu1 dot php dot net | Date: | Thu, 19 Apr 2007 01:55:18 +0000 |
| Subject: | note 74588 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125557@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 194.145.210.3
Probable Submitter: 80.76.201.50
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/74588
Del: integrated -- https://master.php.net/note/delete/74588/integrated
Del: useless -- https://master.php.net/note/delete/74588/useless
Del: bad code -- https://master.php.net/note/delete/74588/bad+code
Del: spam -- https://master.php.net/note/delete/74588/spam
Del: non-english -- https://master.php.net/note/delete/74588/non-english
Del: in docs -- https://master.php.net/note/delete/74588/in+docs
Del: other reasons-- https://master.php.net/note/delete/74588
Reject -- https://master.php.net/note/reject/74588
Search -- https://master.php.net/manage/user-notes.php