Search This Blog

Mar 18, 2014

Auto Detection of CSV EOL using PHP

Different Operating  Systems always find a way to make developers life in uneasy. Just like what happened when we created a import contact script that will parse a csv file then save it to a database.

The script runs smoothly using a Windows CSV format but not with MS DOS format. The problem is with their EOL (end of lines). The MAC options convert the windows CR/LF to the MAC CR only standard and LF when it is used in LINUX. See more detailed variation of csv format here.

(CR - carriage return , LF - line feed)

This runtime setting does it for me. Technically what it does is detecting what EOL configuration of a file have. So no matter what OS you have created teh csv file it PHP will detect it.


 ini_set("auto_detect_line_endings", true);