fgetcsv in PHP fails with Mac-created files
08 01 2010
Today I had a problem importing a CSV file in PHP. It seems that apache doesn't properly regognize the line endings from the csv file.
When CSV the file has been created on a Mac, you will get problems when using fgetcsv to parse CSV files under PHP: The line endings are incorrectly interpreted.
Try the following code:
'auto_detect_line_endings' enables PHP to interoperate with Macintosh systems and look after which line-ending conventions is used.
The common line endings are:
\n (UNIX/Linux)
\n\r (Windows)
\r (Mac)
Here is an wikipedia article about the historical reason behind different line ending at different platforms: Newline History
When CSV the file has been created on a Mac, you will get problems when using fgetcsv to parse CSV files under PHP: The line endings are incorrectly interpreted.
Try the following code:
'auto_detect_line_endings' enables PHP to interoperate with Macintosh systems and look after which line-ending conventions is used.
The common line endings are:
\n (UNIX/Linux)
\n\r (Windows)
\r (Mac)
Here is an wikipedia article about the historical reason behind different line ending at different platforms: Newline History
Written by Martin Mohr
Comments : 3 Comments »
Categories : PHP
Trackbacks : No Trackbacks »






Trackbacks
No Trackbacks