我正在使用此代码列出目录中完美运行的所有文件
<?php
$exclude = array("index.php","cssheadertop.php","cssheaderbottom.php");
$cssfiles = array_diff(glob("*.php"), $exclude);
foreach ($cssfiles as $cssfile) {
$filename = "http://example.com/lessons/css/".$cssfiles[$cssfile];
outputtags($filename,true,true);
}
?>
但是,使用此代码,网页上不会显示任何内容。我无法弄明白为什么
<?php
$exclude = array("index.php","htmlheadertop.php","htmlheaderbottom.php");
$htmlfiles = array_diff(glob("*.php"), $exclude);
foreach ($htmlfiles as $htmlfile) {
$filename = "http://example.com/lessons/html/".$htmlfiles[$htmlfile];
outputtags($filename,true,true);
}
?>
答案 0 :(得分:1)
试试这个:
<?php
$exclude = array("index.php","htmlheadertop.php","htmlheaderbottom.php");
$htmlfiles = array_diff(glob("*.php"), $exclude);
foreach ($htmlfiles as $htmlfile) {
$filename = "http://example.com/lessons/html/".$htmlfile;
outputtags($filename,true,true);
}
?>
$ htmlfiles [$ htmlfile]不应该设置,也不应该有用。
答案 1 :(得分:0)
您需要在foreach循环中使用$htmlfile
而不是$htmlfiles[$htmlfile]
,并且它适用于任何其他变量的名称
<?php
$exclude = array("index.php","htmlheadertop.php","htmlheaderbottom.php");
$htmlfiles = array_diff(glob("*.php"), $exclude);
foreach ($htmlfiles as $htmlfile) {
$filename = "http://example.com/lessons/html/".$htmlfile;
outputtags($filename,true,true);
}
?>