Skip first line of fgetcsv method

后端 未结 6 597
长发绾君心
长发绾君心 2020-11-28 12:25

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 (($emapDa         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 13:28

    You can add a simple check and skip the query if the check fails:

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

提交回复
热议问题