如何逐行读取大文件?我想逐行读取文件,但不需要将其完全加载到内存中。我的文件太大,无法在内存中打开,如果尝试这样做,我总是能够避免内存错误。文件大小为1GB。
3 回答
![?](http://img1.sycdn.imooc.com/5333a0350001692e02200220-100-100.jpg)
繁花如伊
TA贡献2012条经验 获得超12个赞
fgets()
$handle = fopen("inputfile.txt", "r");if ($handle) { while (($line = fgets($handle)) !== false) { // process the line read. } fclose($handle);} else { // error opening the file.}
![?](http://img1.sycdn.imooc.com/54584dc4000118d302200220-100-100.jpg)
MYYA
TA贡献1868条经验 获得超4个赞
if ($file = fopen("file.txt", "r")) { while(!feof($file)) { $line = fgets($file); # do same stuff with the $line } fclose($file);}
- 3 回答
- 0 关注
- 472 浏览
添加回答
举报
0/150
提交
取消