0

こんにちは私はこの基本的なランダム引用スクリプトを持っていますが、配列でページを出力したいと思います。つまり、「echo $ quote」の代わりに、「include('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]);
?>
4

1 に答える 1

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);
    }
}
于 2012-04-04T13:13:51.090 に答える