Mac Newlines Can Cause PHP Headaches

August 31, 2010 at 21:47 (php, web dev)

While working on a project, somehow the majority of my PHP files acquired Mac style \r newline characters rather than DOS/Windows \r\n or UNIX \n. I don’t know exactly how this happened, but the \r newlines were perpetuated by Notepad++, which identified the files as Macintosh and displayed them transparently. The problem is if I take this code:

echo 'hello';

and upload it to the Linux project server (on Go Daddy), it becomes:

<?phpecho 'hello';?>

which of course causes an error. It took a while to trace the problem to its source, mainly because I had no idea such newline characters existed. So now you know, and knowing is half the battle.


Permalink Leave a Comment