how do i parse a csv file to grab the column names first then the rows that relate to it?

前端 未结 7 1220
梦毁少年i
梦毁少年i 2020-11-29 03:42

here is my csv

column1,column2,column3,column4,column5
column1_row1,column2_row1,column3_row1,column4_row1,column5_row1
column1_row2,column2_row2,column3_row         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 04:19

    It looks like it might be taking it all as one line. Perhaps your csv has a different line ending than it should have? At least that's what it looks like in your output. If you look at row 1, column 5 in your result array, it contains a line ending and column 1 in row 2. And the same in the rest. It reads it all in as one line.

    Note: If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem. -- fgetscv

    What platform are you on? Either way, check the line endings.

提交回复
热议问题