Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip first line of fgetcsv method

Tags:

php

I have a CSV file and I read data from CSV file then I want to skip first line of CSV file.Which'll contain any header. I am using this code.

while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
    // Code to insert into database
}

When I insert data into th database then header should not to be saved into the database.

like image 903
please delete me Avatar asked Sep 02 '25 05:09

please delete me


1 Answers

Before beginning the while loop, just get the first line and do nothing with it. This way the logic to test if it's the first line is not needed.

fgetcsv($file, 10000, ",");
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE) {
  //....
}
like image 181
Dustin Currie Avatar answered Sep 04 '25 19:09

Dustin Currie