php读取在线远程txt文档内容到数组并遍历

<?php   
$txt = "http://www.xxx.cn/sitemap.txt"; //读取远程txt;
//是否存在
if(file_get_contents($txt)){
$data = file($txt); //将文件存放在一个数组中;
$num = count($data); //条数;
$id = mt_rand(0,$num-1); //随机数字;
$url = chop($data[$id]); //显示第几行数据,并去除空格;
echo "$url";  //随机显示一条域名
}
echo "</br>";
echo "zongtiaoshu:"."$num";
echo "</br>";
for ($i=0; $i < $num ; $i++) {
    echo $data[$i]."</br>";
}
//header("Location: $url");  //开始随机跳转
?>

主要用于遍历网站在线sitemap.txt内容读取。

猜你喜欢

转载自www.cnblogs.com/secsafe/p/11253474.html