i using function retreive files directory , sub-directories. how can display files _lang.php within directory , sub-directories?
function getdircontents($dir, &$results = array()){ $files = scandir($dir); foreach($files $key => $value){ $path = realpath($dir.directory_separator.$value); if(!is_dir($path)) { $results[] = $path; } else if($value != "." && $value != "..") { getdircontents($path, $results); $results[] = $path; } } return $results; } $dir = './test/'; var_dump(getdircontents($dir));
answered question earlier, try using iterator classes
<?php function getdircontents($directory, $pattern) { $result = array(); $objrecursivedirectoryiterator = new recursivedirectoryiterator($directory, recursivedirectoryiterator::skip_dots); $objrecursiveiteratoriterator = new recursiveiteratoriterator($objrecursivedirectoryiterator); // use regexiterator() grab files match $pattern $objregexiterator = new regexiterator($objrecursiveiteratoriterator, $pattern, recursiveregexiterator::get_match); // iterate through results foreach ($objregexiterator $arrmatches) { $result[] = $arrmatches[0]; } return $result; } $dir = './test/'; $arrdircontents = getdircontents($dir, "~^.+_lang\.php$~i"); var_dump($arrdircontents);
Comments
Post a Comment