Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP scandir获取扩展名为.html的文件列表?_Php - Fatal编程技术网

如何使用PHP scandir获取扩展名为.html的文件列表?

如何使用PHP scandir获取扩展名为.html的文件列表?,php,Php,我正在使用以下代码获取目录中的文件和文件夹列表。 这个很好用。但我需要做的是只获取该目录中HTML文件的列表,而忽略其余的文件和文件夹 这是我的代码: $path = "../"; $files = scandir($path); foreach ($files as &$value) { echo "<a href='http://localhost/".$value."' target='_black' >".$value."</a><br/&g

我正在使用以下代码获取目录中的文件和文件夹列表。 这个很好用。但我需要做的是只获取该目录中HTML文件的列表,而忽略其余的文件和文件夹

这是我的代码:

$path = "../";
$files = scandir($path);
foreach ($files as &$value) {
    echo "<a href='http://localhost/".$value."' target='_black' >".$value."</a><br/>";
}
这对我很有用:

$path = "../";
$files = scandir($path);
$files = glob("*.{html}", GLOB_BRACE);
foreach ($files as &$value) {
    echo "<a href='http://localhost/".$value."' target='_black' >".$value."</a><br/>";
}
$path=“../”;
$files=scandir($path);
$files=glob(“*.{html}”,glob_括号);
foreach($files as&$value){
回声“
”; }
可能会派上用场。我不能肯定这一点。我一直使用
glob()
。您可能可以将其插入您的第一个代码中。旁注:
target=''u black'
应该是
target=''u blank'
,然后尝试下面的答案,并修复相同的打字错误;如果您是从自己的机器上运行这个,请尝试重新启动PHP/Apache。我看不出它怎么能不接受
.tpl.html
文件;莫名其妙,不客气,伙计。
$path = "../";
$files = scandir($path);
$files = glob("*.{html}", GLOB_BRACE);
foreach ($files as &$value) {
    echo "<a href='http://localhost/".$value."' target='_black' >".$value."</a><br/>";
}
$path = "../";
$files = scandir($path);
$files = glob("*.{html}", GLOB_BRACE);
foreach ($files as &$value) {
    echo "<a href='http://localhost/".$value."' target='_black' >".$value."</a><br/>";
}