寻找有关如何将多个html文件从目录加载到没有重复的div的解决方案。
我使用的是愚蠢的代码,但它不是显示html页面,而是简单地列出文件的名称。
非常感谢任何帮助!
<?php
function random_ad($dir = 'includes/ad-swap-box')
{
$indexes=array_rand($files,3);
$file1=$files[$indexes[0]];
$file2=$files[$indexes[1]];
$file3=$files[$indexes[2]];
}
function random_ads($dir = 'includes/ad-swap-box',$howMany=3) {
$files = glob($dir . '/*.html');
if($howMany==0) $howMany=count($files); // make 0 mean all files
$indexes = array_rand($files,$howMany);
$out=array();
if(!is_array($indexes)) $indexes=array($indexes); // cover howMany==1
foreach($indexes as $index) {
$out[]=$files[$index];
}
return $out;
}
$theFiles=random_ads();
?>
<?php echo $theFiles[0]; ?>
<?php echo $theFiles[1]; ?>
<?php echo $theFiles[2]; ?>
答案 0 :(得分:1)
您仍需要包含这些文件:
function displayFiles($theFiles = array()) {
foreach ($theFiles as $theFile) {
include_once($theFile);
}
}
您想要显示它们的位置:
<?php displayFiles($theFiles); ?>