Skip first line of fgetcsv method

后端 未结 6 601
长发绾君心
长发绾君心 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:29

    Try this simple code.

    $file = fopen('example.csv', 'r');  // Here example is a CSV name
    $row = 1;
    while (($line = fgetcsv($file, 10000, ",")) !== FALSE) {
    // $line is an array of the csv elements
    if($row == 1){ $row++; continue; }   // continue is used for skip row 1
    // print_r($line);
    // rest of your code
    }
    

提交回复
热议问题