开发者

Reading huge file line by line in PHP

In Java I use Scanner to read text file line by line, so memory usage will be very low, because only one line is in memory once. Is there similar method in 开发者_如何学JAVAPHP?


use fseek, fgets

$handle = fopen("/tmp/uploadfile.txt", "r") or die("Couldn't get handle");
if ($handle) {
    while (!feof($handle)) {
        $line = fgets($handle);
        // Process line here..
    }
    fclose($handle);
}

Reading very large files in PHP


fgets($fileHandle) is what you're looking for. You get the file handle using fopen("filename.txt", "r"), and close it with fclose($fileHandle).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜