Jump to content

How to get the line number of a CSV file?


lopes_andre

Recommended Posts

There is no real good way of doing it. You'll need to open the file, read the entire thing into an array, count the size of the array, then loop back through 9the array) until you get to the line you want.

 

You'll probably have no use for fgetcsv by then.

Hi,

 

Thanks for the reply.

 

It is a good idea to store in one array 200MB of data or should be better to get the lines of the CSV one by one?

 

The deal is that I have a 200MB CSV file that I need to write the INSERT's INTO to put in the database, but I don't know if it is a good idea to store the data in one array or construct the INSERTS one by one in a loop.

 

Best Regards,

 

Detecting the first line and either skipping over it or reading the field names from it has nothing to do with a count of the number of the total lines or the ability to goto line x. I would say you are over complicating this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.