Function introduction:
resource fopen($path, $math)
Open a file, $path is the path, $math is the method, Returns a resource handle.
string fgets(resource $handle[,int $length])
Read a line from the file pointer, $handle is the resource handle, and return a line of text content.
bool feof(resource $handle)
Function detects whether the end of the file has been reached.
Free video tutorial recommendation: php video tutorial
ceshi.txt file content
111111111111111 22222222222222 33333333333333 44444444444444 55555555555555 66666666666666
The example code is as follows:
$handle = fopen('./ceshi.txt',"r");//以只读方式打开一个文件 $i = 0; while(!feof($handle)){//函数检测是否已到达文件末尾 if(fgets($handle)){// 从文件指针中读取一行 $i++; }; } echo $i;//6 fclose($handle);
Related Recommended article tutorials: php tutorial
The above is the detailed content of How to read the number of lines of a large file in php. For more information, please follow other related articles on the PHP Chinese website!