php fgetcsv fails to detect line endings in macintosh csv files

I was recently working on a php script to import csv file data into a MySQL table. I was getting odd results in my table, and it appeared to me that the script was not respecting the line endings in the csv file.

After trying a lot of different solutions I found some information regarding the

ini_set

command in php. The information indicated that fgetcsv fails to detect line endings in macintosh created csv files. I found documentation on php.net that talked about this issue. The solution is to add the following line above your

fopen()

command.

ini_set('auto_detect_line_endings', true);
This entry was posted in PHP. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>