简体   繁体   English

目录中目录内的php html文件

[英]php html files within directorys within a directory

I am trying to find all html files within directories in a root directory, I have an array with all the directories in and I'm trying to loop through each directory in the array to find the files and create a list but it is not working, any ideas? 我试图在根目录中的目录中找到所有html文件,我有一个包含所有目录的数组,并且试图遍历数组中的每个目录以查找文件并创建列表,但是它不起作用, 有任何想法吗?

$dirs = glob("/Root_directory*", GLOB_ONLYDIR);

foreach($dirs as $dir) {
    $phpfiles = glob($dir . "*.html");

    foreach($phpfiles as $phpfile) {
        echo "<a href=$phpfile>".basename($phpfile)."</a>";
    }
}

I also tried the approach recommended here using recursion and this gave an empty array 我也试过推荐的方式在这里使用递归,这给了一个空数组

$Directory = new RecursiveDirectoryIterator('path/to/project/');
$Iterator = new RecursiveIteratorIterator($Directory);
$Regex = new RegexIterator($Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);

This is the recursive method that works after a lot of fiddling. 这是经过反复摆弄后才能起作用的递归方法。

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path),        RecursiveIteratorIterator::SELF_FIRST);
$Regex = new RegexIterator($objects, '/^.+\.html$/i', RecursiveRegexIterator::GET_MATCH);
foreach($Regex as $name => $Rege){
echo "<a href=$name>".$name."</a> \n";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM