Edgardo DelTabarnaco
Edgardo DelTabarnaco

Reputation: 31

Am I dreaming or do carriage returns prevent PHP versions from seeing a code line?

I recently discovered that code lines with only a "CR" instead of a "CRLF" or "LF" at the end of the line are causing PHP to behave weirdly, namely seeing 2 lines as one, ignoring the CR or, more accurately, interpreting it as what it is: a carriage return but not a linefeed.

I had never had that problem before but, lately, I discovered that notepad++ sometimes put only a CR when I hit "Enter" to move to a new line... it causes the script to behave badly.

For example, this Hello World script works fine when lines are eneded with LF or CRLF but crashes with just CRs (at least i replicate that problem on both a peer1 and hostgator servers -- does somebody else have a different experience?)...

<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.cnn.com/" );
?>

and i get this error:

Fatal error: Call to undefined function phpheader() in /home/bernatch/public_html/test-redir-cr.php on line 1

Obviously, PHP is seeing the <?php code and the Header function as being on the same line...

My question is: a) is there a way to force PHP to interpret a single CR as a truly different line

or

b) is there a way to force notepad++ to put CRLF or LF whenever I press Enter?

Upvotes: 3

Views: 174

Answers (2)

taco
taco

Reputation: 1373

Macs use CR. Linux uses LF. Windows uses CR-LF, so it would be very odd for the Windows operating system to not insert an LF after the CR. Maybe I am missing something here.

Edited on Windows -> Viewed on Linux = OK

Edited on Windows -> Viewed on Mac = OK

So I'm guessing it could be your FTP client. Make sure to upload plain text files as ASCII, not binary.

Upvotes: 1

jeffjenx
jeffjenx

Reputation: 17457

In Notepad++, you should be able to do an EOL conversion to Windows Format, as reported in this SuperUser.com answer.

Upvotes: 0

Related Questions