Random Quotes Script on a timer?

2019-09-06 18:31发布

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条回答
Juvenile、少年°
2楼-- · 2019-09-06 19:00

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);
    }
}
查看更多
登录 后发表回答