我正在尝试创建新闻门户网站。 我想加载list.txt文件中的随机新闻链接 并创建了一个调用list.txt的php脚本,并从列表中加载链接。
结帐我的代码。
的script.php
<?php
$loadlist = explode("\n", file_get_contents('list.txt'));
$rand = rand(0,count($loadlist)-1);
// Here is our random link URL
$picked = $loadlist[$rand];
?>
<meta http-equiv="refresh" content="2;url=<?php echo $picked; ?>">
LIST.TXT
http://news.com/news1.html
http://news.com/news2.html
http://news.com/news3.html
http://news.com/news4.html
http://news.com/news5.html
上面的代码工作正常,谢谢
答案 0 :(得分:2)
根据$loadlist
数组的项目数获取随机整数。
$loadlist = explode("\n", file_get_contents('list.txt'));
$rand = rand(0,count($loadlist)-1);
// Here is our random link URL
$picked = $loadlist[$rand];