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

后端 未结 8 1434
暖寄归人
暖寄归人 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:38

    Rather than using if condition for checking whether it is the first row, a better solution is to just add an extra line of code before the line from where the while loop starts as shown below :

    ....
    .....
    fgetcsv($handle);//Adding this line will skip the reading of th first line from the csv file and the reading process will begin from the second line onwards
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    .......
    .......
    

    It is just as simple......

提交回复
热议问题