Random Quotes Script on a timer?

只愿长相守 提交于 2019-12-12 03:09:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!