mardi 17 mai 2016

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.

I am using the fooling code, but instead of displaying the html pages, it simply lists the name of the files.

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




Aucun commentaire:

Enregistrer un commentaire