2012-04-04 33 views
0

嗨,我有这个基本的随机引用脚本,但我希望它在一个数组中输出页面,而不是“echo $ quote”,做一些数组与“包括('text.php,text2.php, text3.php');”等等。随机引用定时器上的脚本?

不太确定该怎么做。有任何想法吗?

我也想定时器成为突出的选择功能,所以它从列表中选择循环,而不是随机抽取。

谢谢:)

<?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]); 
?> 
+0

包含的文件包含哪些内容? – Baba 2012-04-04 13:12:37

+0

只是html页面 – GibsonFX 2012-04-04 13:26:59

+0

你已经给了一个解决方案..这是你说的感谢你..你还想要什么?你应该做的是接受或更新你的问题,你需要更多 – Baba 2012-04-04 15:26:13

回答

0

保存在一个数组你的页面。然后用foreach迭代它。 用应包含的网站编号替换$ siteId

$pages = array(1 => 'text.php1', 2 => 'text.php2', 3 => 'text3.php', 4 => 'text4.php'); 

foreach($pages as $pagekey => $page){ 
    if($pagekey == $siteId){ 
     include($page); 
    } 
} 
+0

谢谢,我假设文件扩展后输入一个数字是一个错字? – GibsonFX 2012-04-04 13:28:32

+0

哦,是的。那是一个错字。对不起, – Slemgrim 2012-04-04 15:08:35

+0

我如何在脚本中实现这一点,我无法弄清楚......干杯 – GibsonFX 2012-04-04 15:14:03