Excel Line Endings Break PHP


Excel Line Endings Break PHP

Here’s a quick tip that might save the PHP developers out there some time. (It would have saved me thirty minutes of debugging if I had know this earlier.)

When you export an Excel file as a CSV in Office for Mac, Excel saves the file using CR line breaks instead of the standard LF (Unix) or CRLF (Windows) endings. CR’s will break PHP’s fgetcsv() function. So, before you attempt to parse the CSV file, make sure you convert it to the appropriate line endings.

More info about issues detecting line endings in PHP is available here.

Comments are closed on this post