note 41123 deleted from function.glob by danbrown
| From: | danbrown@php.net | Date: | Mon, 20 Jun 2011 15:20:33 +0000 |
| Subject: | note 41123 deleted from function.glob by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180741@lists.php.net to get a copy of this message | ||
Note Submitter: Paul Gregg / Qube #efnet
----
Just threw this together in response to a common question in irc:
Available at: http://www.pgregg.com/projects/
http://www.pgregg.com/projects/php/code/preg_find.phps
preg_find() - A function to search in a directory for files or directories matching a preg_ pattern.
Tell it the pattern, the start directory and some optional flags and it will return an array of
files and their associated stat() details. If you just want the filenames, just do an array_keys()
on the result.
e.g. $files = preg_find("/\.php$/", '.', PREG_FIND_RECURSIVE);
will find all files ending in .php in the current directory and below.
Options are:
// PREG_FIND_RECURSIVE - go into subdirectorys looking for more files
// PREG_FIND_DIRMATCH - return directorys that match the pattern also
// PREG_FIND_FULLPATH - search for the pattern in the full path (dir+file)
// PREG_FIND_NEGATE - return files that don't match the pattern
// to use more than one simple seperate them with a | character
Hope you find it useful.
Paul.