Alex
Alex

Reputation: 68470

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

The file has text content like:

123
abc
def    

xyz
bla bla
...

I want to read it into an array like file() does, but only until it meets a new line.

So in the example above the array should have 123, abc and def lines in it, that's it.

Is it possible without reading the entire file in the array, because I have quite a few of them and each has 100-120 K?

The first lines are the file headers, so I only need the headers to display generic info for many files.

Upvotes: 0

Views: 161

Answers (1)

Rens Verhage
Rens Verhage

Reputation: 5857

You should use fgets() to read a single line, see: http://php.net/manual/en/function.fgets.php

Upvotes: 2

Related Questions