嗨,我正在尝试使用Php列出特定目录中的所有html和XML格式。
我尝试了以下操作:我仅显示html成功,但是不能包含XML。
可以帮助我吗:
这是我尝试过的方法:如何将.xml添加到以下过滤器中。
<?php
include("lock.php");
$myDirectory = opendir(".");
while ($entryName = readdir($myDirectory))
{
if ($entryName != "." && strtolower(substr($entryName, strrpos($entryName, '.') + 1)) == 'html')
{
$dirArray[] = $entryName;
}
}
closedir($myDirectory);
$indexCount = count($dirArray);
Print ("$indexCount files<br>\n");
sort($dirArray);
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print("<TR><TH>S.No</TH><TH>Filename</TH></TR>\n");
for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != ".")
{
print("<TR><td>");
print($index + 1);
print("</td>");
print("<TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
print("</TR>\n");
}
}
print("</TABLE>\n");
?>
容易,使用glob
查找与模式匹配的路径名,可以将其视为数组
$dirArray = glob("*.{html,HTML,xml,XML}",GLOB_BRACE);
$indexCount = count($dirArray);
Print ("$indexCount files<br>\n");
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print("<TR><TH>S.No</TH><TH>Filename</TH></TR>\n");
for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != ".")
{
print("<TR><td>");
print($index + 1);
print("</td>");
print("<TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
print("</TR>\n");
}
}
print("</TABLE>\n");
此解决方案照顾小写大写文件扩展名模式
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句