我使用以下代码来获取目录中的文件和文件夹列表。这很好。但是我需要做的是只获得该目录下的HTML文件列表,而忽略其余的文件和文件夹。
这是我的代码:
$path = "../";
$files = scandir($path);
foreach ($files as &$value) {
echo "<a href='http://localhost/".$value."' target='_black' >".$value."</a><br/>";
}
我试过了,仍然得到所有的文件和文件夹:
$indir = scandir('../');
$fileextensions = array(".", "html");
$indir = array_diff($indir, array('.', '..'));
$replaceextensions = str_replace($fileextensions, "", $indir);
foreach ($indir as &$value) {
echo "<a href='http://localhost/".$value."' target='_black' >".$value."</a><br/>";
}
有人能给点建议吗?
感谢编辑:下面的代码,我可以得到html文件的列表示例(page1.html, page2.html
等)。然而,我的一些html文件的名字像page1.tpl.html
, page2.tpl.html
等,我不能得到这些文件在列表中,即使他们的扩展名以.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/>";
}