计时器上的随机报价脚本? [英] Random Quotes Script on a timer?
问题描述
我有这个基本的随机引用脚本,但我希望它以数组的形式输出页面,即不是echo $quote",而是使用include('text.php, text2.php"做某种数组, text3.php');"等
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.
谢谢:)
<?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]);
?>
推荐答案
将您的页面保存在一个数组中.然后用foreach遍历它.将 $siteId 替换为应包含的站点编号
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);
}
}
这篇关于计时器上的随机报价脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!