PHP dynamically create CSV: Skip the first line of a CSV file

后端 未结 8 1387
暖寄归人
暖寄归人 2020-12-05 13:19

I am trying to import a CSV file. Due to the program we use, the first row is basically all headers that I would like to skip since I\'ve already put my own headers in via

相关标签:
8条回答
  • 2020-12-05 13:56

    Please use the following lines of code

    $flag = true;
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    if($flag) { $flag = false; continue; }
    //your code for insert
    }
    

    Having the flag variable as true and setting it to false will skip the first line of the CSV file. This is simple and easy to implement.

    0 讨论(0)
  • 2020-12-05 14:04

    this worked for me:

    $count = 0;
    
    while(! feof($file))
    
          {
    
              $entry = fgetcsv($file, 0, ';');
    
              if ($count > 0) {
              //skip first line, header
    
    
              }
    
          $count++;
    }
    
    0 讨论(0)
提交回复
热议问题