fgetcsv fails to read line ending in mac formatted csv file, any better solution?

后端 未结 2 1740
长发绾君心
长发绾君心 2021-01-31 13:51

I was parsing a csv file using php with fgetcsv function. It parsed all content in a line, later i found, csv contains carraige return as \"\\r\". I saw - it was reported as php

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 14:17

    \r line endings are created by Microsoft Excel when saving as a CSV file, so there is not much getting around that if you are starting with an Excel spreadsheet.

    Using auto_detect_line_endings works fine, or you can normalize line endings with preg_replace("/\r\n|\n\r|\n|\r/", "\n", $subject);

提交回复
热议问题