简体   繁体   English

将多个HTML文件加载到div中,而无需使用PHP复制

[英]Load multiple html files into div with no duplication with PHP

Looking for an solution on how to load multiple html files from a directory into a div with no duplication. 寻找一种解决方案,如何将多个html文件从目录加载到div中而不重复。

I am using the fooling code, but instead of displaying the html pages, it simply lists the name of the files. 我使用的是愚弄的代码,但没有显示html页面,而是仅列出了文件名。

Any help would be greatly appreciated! 任何帮助将不胜感激!

<?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]; ?>

You will still need to include the files: 您仍然需要包括以下文件:

function displayFiles($theFiles = array()) {
    foreach ($theFiles as $theFile) {
        include_once($theFile);
    }
}

Where you want to display them do: 您想在哪里显示它们:

<?php displayFiles($theFiles); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM