1

Don't get me wrong, I'm not bothered about the pre PHP 5.3.0 xhtml <br /> tags, and I can easily replace the \r\n with \n, of course.

Thing is I want some sort of global setting on this pre PHP 5.3.0 server to make all similar built in PHP functions to understand that a correct line break between the HTML lines I want to output is a \n, not a \r\n.

Do I want what I shouldn't want? Is it an impossible dream? Or did I just forget the ungooglable constant. There are no end to the questions.

Either way, just an answer to the one in subject would make me happy :) Is it possible, or do I have to str_replace the entire article string once I've built it. Thanks. BTW, Elvis lives. Or at least, 'lives' is an anagram of 'elvis' which is good enough for me since I wasn't really a fan.

In short, I want to save a byte per newline in the HTTPRESULT.

Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63
  • 1
    Is all of this unnecessary noise a consequence of you not being able to get your original question through the low-quality filter? – Robert Harvey May 11 '14 at 02:47
  • 2
    php's probably returning PHP_EOL, which is platform-dependent. if you're on windows, you'll get `\r\n`. – Marc B May 11 '14 at 02:48
  • Robert Harvey: No, the unnecessary noise is due to me being in a good mood! After searching on google and SO. Trick question: are comments that don't ask more detail or make suggestions considered unnecessary noise? ;) Marc B: PHP_EOL is for reading. PHP, which produces the \r\n output, is running on a standard shared hosting Apache server. – Henrik Erlandsson May 11 '14 at 03:01

1 Answers1

0

nl2br() uses whatever line endings were present in its input. If you don't want to see \r\n in the output, convert it to \n before you pass it in.

This isn't explicitly stated in the documentation for this function, but it's implied heavily by the description, which reads (emphasis mine):

Returns string with '<br />' or '<br>' inserted before all newlines (\r\n, \n\r, \n and \r).

And it's borne out by testing.