note 90278 added to function.glob
| From: | me at lx dot sg | Date: | Tue, 14 Apr 2009 14:15:52 +0000 |
| Subject: | note 90278 added to function.glob | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153207@lists.php.net to get a copy of this message | ||
Referring to the recursive glob() function below
(http://sg.php.net/manual/en/function.glob.php#87221):
It does not work when the pattern contains a directory name. Here's a fixed version:
<?php
function rglob($pattern, $flags = 0, $path = '') {
if (!$path && ($dir = dirname($pattern)) != '.') {
if ($dir == '\\' || $dir == '/') $dir = '';
return rglob(basename($pattern), $flags, $dir . '/');
}
$paths = glob($path . '*', GLOB_ONLYDIR | GLOB_NOSORT);
$files = glob($path . $pattern, $flags);
foreach ($paths as $p) $files = array_merge($files, rglob($pattern, $flags, $p . '/'));
return $files;
}
?>
----
Server IP: 202.79.181.100
Probable Submitter: 219.74.191.110
----
Manual Page -- http://www.php.net/manual/en/function.glob.php
Edit -- https://master.php.net/note/edit/90278
Del: integrated -- https://master.php.net/note/delete/90278/integrated
Del: useless -- https://master.php.net/note/delete/90278/useless
Del: bad code -- https://master.php.net/note/delete/90278/bad+code
Del: spam -- https://master.php.net/note/delete/90278/spam
Del: non-english -- https://master.php.net/note/delete/90278/non-english
Del: in docs -- https://master.php.net/note/delete/90278/in+docs
Del: other reasons-- https://master.php.net/note/delete/90278
Reject -- https://master.php.net/note/reject/90278
Search -- https://master.php.net/manage/user-notes.php