将文件读入数组,但只能读到某个点


Read a file into array, but only until a certain point

该文件具有如下文本内容:

123
abc
def    
xyz
bla bla
...

我想像 file() 一样将其读入数组,但仅在它遇到新行之前。

所以在上面的例子中,数组应该有 123、abc 和 def 行,就是这样。

是否可以不读取数组中的整个文件,因为我有相当多的文件,每个文件都有 100-120 K?

第一行是文件头,所以我只需要头来显示许多文件的通用信息。

你应该使用 fgets() 来读取一行,请参阅:http://php.net/manual/en/function.fgets.php