php读取文件行数方法

先让我们了解下基本的文件操作函数

resource fopen($path,$math) 打开一个文件,$path 是路径,$math是方法,返回一个资源句柄

string fgets ( resource $handle [, int $length ] ) 从文件指针中读取一行,$handle是资源句柄,返回一行文本内容

bool feof ( resource $handle )   函数检测是否已到达文件末尾 ,返回

ceshi.txt 文件内容

111111111111111
22222222222222
33333333333333
44444444444444
55555555555555
66666666666666
$handle = fopen('./ceshi.txt',"r");//以只读方式打开一个文件
$i = 0;
while(!feof($handle)){//函数检测是否已到达文件末尾 
    if(fgets($handle)){// 从文件指针中读取一行
        $i++;
    };
}
echo $i;//6
fclose($handle);
原文地址:https://www.cnblogs.com/zxqblogrecord/p/8489880.html