nl2br returns <br />\r\n, how to make all built in PHP functions return \n instead?

StackOverflow https://stackoverflow.com/questions/23588405

  •  19-07-2023
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top