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:

<?php
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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: