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.
Isn't that just what is historically referred to as "Mac line endings"? I have had to type the following too many times in the past: $string = str_replace("\r","\n",str_replace("\r\n","\n",$string));
Jackson
05/24/06
12:37 pm
Isn't that just what is historically referred to as "Mac line endings"? I have had to type the following too many times in the past: $string = str_replace("\r","\n",str_replace("\r\n","\n",$string));
Jackson
05/24/06
12:37 pm
I agree that the headline might be misleading, but the basic point that platform-specific line endings still matter and the reference to related information in PHP still have value.
Thomas O'Connell
05/25/06
03:11 pm
I agree that the headline might be misleading, but the basic point that platform-specific line endings still matter and the reference to related information in PHP still have value.
Thomas O'Connell
05/25/06
03:11 pm
I wasn't trying to expose a flaw in PHP or Excel with this post. It was just meant to help other PHP developers avoid 30 extra minutes of debugging that I had to go through :)
Tyler Hall
05/25/06
03:15 pm
I wasn't trying to expose a flaw in PHP or Excel with this post. It was just meant to help other PHP developers avoid 30 extra minutes of debugging that I had to go through :)
Tyler Hall
05/25/06
03:15 pm
Official method of the Telalink Intern program: perl -pi.bak -e "s/\r/\n/g;" file.txt
Scott
05/25/06
05:33 pm
Here's a shell command that might help: tr \r \n /path/to/new_script From: http://www.macdevcenter.com/pub/a/mac/2003/11/07/scripting_osx.html
Jason Wehmhoener
05/08/07
07:37 pm
Thanks for the post. This was pissing me off to no end.
Ron
12/03/07
07:08 pm

