0

I did not ask about How to replace \r & \n with <br/>?, I need to know how to dump line endings.

I have a script that handles post data incoming from users that fill a form. How can I dump line endings if the data may contain different types of ones (CR, CRLF, LF)?

When using the var_dump function, it displays something like

string(3) "


"

And the second question: what happens if users have different OS? Will a browser send different types of line endings that are typical for these OS?

El cero
  • 607
  • 5
  • 13
  • for html you need to use a `
    ` tag whitespace (including newlines) is collapsed when rendering html in the browser. (View source and you will see your newlines are alive and well)
    – Orangepill Aug 13 '15 at 19:25
  • If the output is a webpage, then you'll need to use `
    ` mostly, not CR/LF combinations. Browsers typically send network linebreaks (CRLF).
    – mario Aug 13 '15 at 19:25
  • as usual "be liberal in what you receive, strict in what you output". expect to get ANY kind of line endings, and convert as necessary. – Marc B Aug 13 '15 at 19:26
  • 1
    So, are you saying you want to actually see the \n? You could do str_replace(array("\r\n","\n\r","\r","\n"),"\\n\n",$str), which would replace all occurrences of line breaks with a visible \n (thanks to the double slash), and a new line. Or for more control, you might be able to use a preg_replace, or something. – Reed Aug 13 '15 at 19:39
  • 1
    @Jakar, yes I asked about that. Thank you for your answer. – El cero Aug 13 '15 at 19:41
  • 1
    If your question was about converting CR/LF back to escapes for visualization, then the better references would be: [PHP - print string with control characters](http://stackoverflow.com/q/6727955), or: [PHP: is there a way to see "invisible" characters like \n](http://stackoverflow.com/q/9345841) – mario Aug 13 '15 at 19:53

0 Answers0