2012-04-04 36 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