Peuplarchie Posted January 31, 2010 Share Posted January 31, 2010 Good day to you all, is there a way that I can use glob recursive ly in the following code ? <?PHP foreach(glob('Photos/*', GLOB_ONLYDIR) as $dir) { echo '<b>'.$dir.'</b><br>'; } ?> Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/190425-recursive-glob/ Share on other sites More sharing options...
premiso Posted January 31, 2010 Share Posted January 31, 2010 From the glob site at php.net a user contribution: Contributed by php at hm2k.org <?php // $Id: rglob.php,v 1.0 2008/11/24 17:20:00 hm2k Exp $ /** * Recursive glob() */ /** * @param int $pattern * the pattern passed to glob() * @param int $flags * the flags passed to glob() * @param string $path * the path to scan * @return mixed * an array of files in the given path matching the pattern. */ function rglob($pattern='*', $flags = 0, $path='') { $paths=glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT); $files=glob($path.$pattern, $flags); foreach ($paths as $path) { $files=array_merge($files,rglob($pattern, $flags, $path)); } return $files; } /* example usage: */ chdir('../'); var_export(rglob('*.php')); ?> Quote Link to comment https://forums.phpfreaks.com/topic/190425-recursive-glob/#findComment-1004492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.