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

Musa picture Musa · Dec 27, 2010 · Viewed 22.6k times · Source

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 bug before. I've solved this by setting php runtime configuration which is -

ini_set("auto_detect_line_endings", "1");

is there any more solution or is this the right way?

Thanks

Answer

phihag picture phihag · Dec 27, 2010

Setting auto_detect_line_endings is explicitly recommended by the php documentation.

However, I cannot fathom why you would want to delimit lines with \r in 2010. If possible, convert them to the UNIX-style \n.