【问题标题】:Random Quotes Script on a timer?计时器上的随机报价脚本?
【发布时间】:2012-04-04 12:59:07
【问题描述】:

您好,我有这个基本的随机引用脚本,但我希望它以数组的形式输出页面,即代替“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]);
?>

【问题讨论】:

  • 包含的文件中有什么???
  • 你已经给出了一个解决方案..你说谢谢..你还想要什么???你应该做的是接受或更新你需要更多的问题
  • 在您提供帮助后,我删除了此评论。对不起

标签: php random timer timer-jobs


【解决方案1】:

将您的页面保存在一个数组中。然后用 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);
    }
}

【讨论】:

  • 谢谢,我认为文件扩展名后面的数字是错字?
  • 哦,是的。那是一个错字。对此感到抱歉
  • 如何在脚本中实现这个,我想不通...干杯
猜你喜欢
  • 1970-01-01
  • 2012-02-27
  • 2020-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-21
  • 1970-01-01
相关资源
最近更新 更多