簡體   English   中英

將多個HTML文件加載到div中,而無需使用PHP復制

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

尋找一種解決方案,如何將多個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]; ?>

您仍然需要包括以下文件:

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

您想在哪里顯示它們:

<?php displayFiles($theFiles); ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM