猿问
如何逐行读取大文件?
如何逐行读取大文件?
我想逐行读取文件,但不需要将其完全加载到内存中。
我的文件太大,无法在内存中打开,如果尝试这样做,我总是能够避免内存错误。
文件大小为1GB。
慕神8447489
浏览 473
回答 3
3回答
繁花如伊
您可以使用fgets()函数逐行读取文件:$handle = fopen("inputfile.txt", "r");if ($handle) { while (($line = fgets($handle)) !== false) { // process the line read. } fclose($handle);} else { // error opening the file.}
0
0
0
MYYA
if ($file = fopen("file.txt", "r")) { while(!feof($file)) { $line = fgets($file); # do same stuff with the $line } fclose($file);}
0
0
0
随时随地看视频
慕课网APP
相关分类
PHP
php如何把参数放在Http Request Heade????
1 回答
我要回答