我使用以下代码:
<?php include("news/news05.php"); ?>
<?php include("news/news04.php"); ?>
<?php include("news/news03.php"); ?>
<?php include("news/news02.php"); ?>
<?php include("news/news01.php"); ?>
有没有一种自动递增包含的方法?例如,如果我在我的文件中添加了一个名为“new06.php”的新页面?
顺便说一句,有没有一种方法可以用一行包含多个页面?
谢谢你的帮助。
本杰
发布于 2014-12-30 19:49:23
您可以使用此解决方案:
<?php
for ($i = 1; $i <= 6; $i++) {
$fname = "news/news0{$i}.php";
if (file_exists($fname)) {
include($fname);
}
}
?>
只需根据您的需要修改它。
发布于 2014-12-30 19:51:34
当我不得不这么做的时候,我会这样做:
$files = glob('news/news*[0-9].php', GLOB_BRACE);
natcasesort($files);
foreach ($files as $newsFile) {
require_once($newsFile);
}
欲了解更多信息,请访问PHP: glob function manual
发布于 2014-12-30 19:55:16
没有办法为包含多个文件编写一个包含
将所有的include放在一个文件中并包含该文件,或者为此创建循环
,但在我看来,要保持简单,为每个文件写一行
https://stackoverflow.com/questions/27704887
复制相似问题