如何使用php脚本读取30MB文本文件?

leo*_*eon 1 php text loops file

嗨我有一个大小高达30MB的文本文件我想使用PHP循环脚本读取此文件

$lines = file('data.txt');

//loop through each line
foreach ($lines as $line) { \\some function }
Run Code Online (Sandbox Code Playgroud)

有什么办法吗?我想打开它来阅读php不允许我打开一个30MB的文件.

xil*_*il3 6

你可以像这样逐行阅读:

$file = fopen("data.txt", "r") or exit("Unable to open file!");

while(!feof($file)) {
  // do what you need to do with it - just echoing it out for this example
  echo fgets($file). "<br />";
}

fclose($file);
Run Code Online (Sandbox Code Playgroud)