PHP读取txt文本前10条数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wuxianbing2012/article/details/86648558
    /**
     * 读取txt前100行
     */
    public function readTxt()
    {
        $open=file_get_contents(ROOT_PATH.'NAME.txt');
        //把robots.txt整个文件当做字符串存在$open变量里
        $arr=explode("\r\n",$open);
        /*按照windows换行作为分割条件,分割$open变量
        换行:linux的\r,unix的时\n,windows是\r\n,html里是<br>
        */
        //shuffle($arr);
        //打乱数组
        for($i=0;$i<10;$i++)
        //循环,这回是输出$arr2的10条
        {
            echo $arr[$i].'<br>';
        }
    }

猜你喜欢

转载自blog.csdn.net/wuxianbing2012/article/details/86648558