Quasipickle
Quasipickle

Reputation: 4498

How to skip multiple lines when reading from a file pointer in PHP

I have a somewhat irregularly structured CSV file I'm reading with fopen() and fgetcsv(). The first 5 lines are to be discarded.

Is there an efficient way to discard those 5 lines? What I have now is:

$fp = fopen($path,'r');
fgets($fp);fgets($fp);fgets($fp);fgets($fp);fgets($fp);

which gets the job done, but seems dirty.

Upvotes: 0

Views: 156

Answers (1)

ArtisticPhoenix
ArtisticPhoenix

Reputation: 21661

So like this

 $CSV = new SplFileObject($file);
 $CSV->seek(5);
 $row = $CSV->fgetcsv();

Upvotes: 6

Related Questions