note 114024 added to function.glob
| From: | rene dot rathmann at gmx dot de | Date: | Thu, 02 Jan 2014 11:05:06 +0000 |
| Subject: | note 114024 added to function.glob | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198071@lists.php.net to get a copy of this message | ||
You can do a recursive file search with yield.
<?php
function findAllDirs($start) {
$dirStack=[$start];
while($dir=array_shift($dirStack)) {
$ar=glob($dir.'/*',GLOB_ONLYDIR|GLOB_NOSORT);
if(!$ar) continue;
$dirStack=array_merge($dirStack,$ar);
foreach($ar as $DIR)
yield $DIR;
}
}
$fname='*.php';
$result=[];
foreach(findAllDirs('/var/www/localhost') as $dir) {
$match=glob($dir.'/'.$fname,GLOB_NOSORT);
if(!$match) continue;
$result=array_merge($result,$match);
}
print_r($result);
?>
----
Server IP: 87.106.1.137
Probable Submitter: 217.9.60.196
----
Manual Page -- http://php.net/manual/en/function.glob.php
Edit -- https://master.php.net/note/edit/114024
Del: integrated -- https://master.php.net/note/delete/114024/integrated
Del: useless -- https://master.php.net/note/delete/114024/useless
Del: bad code -- https://master.php.net/note/delete/114024/bad+code
Del: spam -- https://master.php.net/note/delete/114024/spam
Del: non-english -- https://master.php.net/note/delete/114024/non-english
Del: in docs -- https://master.php.net/note/delete/114024/in+docs
Del: other reasons-- https://master.php.net/note/delete/114024
Reject -- https://master.php.net/note/reject/114024
Search -- https://master.php.net/manage/user-notes.php