问题
Hi I have this basic random quote script, but I would like it to output pages in an array, i.e. instead of "echo $quote", do some sort of array with "include('text.php, text2.php, text3.php');" etc.
not quite sure how to do it. Any ideas?
I would also like the timer to become the prominent selection feature so it chooses from a list that cycles, rather than is pulled at random.
Thank you :)
<?php
$cachefile = './current_t_id';
$time = $id = null;
$change_every = 3600;
include('text.php');
if(is_file($cachefile)) {
list($time, $id) = explode(' ', file_get_contents($cachefile));
}
if(!$time || time() - $time > $change_every) {
srand ((double) microtime() * 100000);
$id = rand(0,count($quotes)-1);
file_put_contents($cachefile, time().' '.$id); // update cache
}
echo ($quotes[$id]);
?>
回答1:
save your pages in an array. then iterate trough it with foreach. replace $siteId with the number of the site which should be included
$pages = array(1 => 'text.php1', 2 => 'text.php2', 3 => 'text3.php', 4 => 'text4.php');
foreach($pages as $pagekey => $page){
if($pagekey == $siteId){
include($page);
}
}
来源:https://stackoverflow.com/questions/10011620/random-quotes-script-on-a-timer