2016-05-17 5 views
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]; ?> 

答えて

1

あなたはまだファイルをインクルードする必要があります。

あなたがそれらが何を表示したい
function displayFiles($theFiles = array()) { 
    foreach ($theFiles as $theFile) { 
     include_once($theFile); 
    } 
} 

<?php displayFiles($theFiles); ?> 
+0

が魅力のように働きました! PHPを使い始めたばかりで、あなたの助けが大変ありがとうございます! – VermontDC

+0

@VermontDCそれを聞いてうれしい。私があなたを助けてくれたと感じたら、私の答えに最高の答えを記入してください。 ;) – Peter

関連する問題