You are here:  » Skip a Specifc Line Number


Skip a Specifc Line Number

Submitted by medicalendar on Mon, 2007-07-23 18:23 in

This question is related to my previous question about starting on a specific line, but deals with skipping optional lines in the file.

I have a .csv file that starts on line 10 with the header row, the next line (11) is a summary row with totals for each column, and then line 12 contains the data I want to parse. Is there anyway to start on line 10 - to get the header fields, skip line 11 and then continue parsing on line 12?

I know this isn't a very common scenario, but one of my vendors has their .csv file set up this way, and won't budge.

Thanks!

Jeremy

Submitted by support on Mon, 2007-07-23 18:27

Hi Jeremy,

This isn't something that can be handled easily by the parser, but you can deal with it quite easily in your record handler function. In this case, all you have to do is use a global counter to recognise that it is the first record and ignore it. You can then carry on with subsequent records as normal. For example:

  $record = 0;
  function myRecordHandler($record)
  {
    global $record;
    $record++;
    if ($record == 1) return; // skip first record
    // continue as normal with subsequnt records
  }

Hope this helps!
Cheers,
David.

Submitted by medicalendar on Mon, 2007-07-23 18:33

That makes perfect sense. Thanks again for the speedy reply.

Best,

Jeremy