0
複数のhtmlファイルをディレクトリから重複のないdivに読み込む方法を探しています。複数のhtmlファイルをPHPと重複しないで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]; ?>
が魅力のように働きました! PHPを使い始めたばかりで、あなたの助けが大変ありがとうございます! – VermontDC
@VermontDCそれを聞いてうれしい。私があなたを助けてくれたと感じたら、私の答えに最高の答えを記入してください。 ;) – Peter