douxie7738 2017-02-16 10:39 采纳率: 0%
浏览 47

目录中directorys内的php html文件

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?

$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);
  • 写回答

1条回答 默认 最新

  • dozabt4329 2017-02-16 11:02
    关注

    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> 
    ";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向