0

Is there any way to have PHP output a string with the \r\n and \n's as actual text instead of linebreaks? I'm seeing an interesting issue where an explode() on \n's isn't running properly on a Windows server...

EDIT: The \r\n's are coming from a user pressing enter when typing into a textarea so there's nothing for me to escape...

2
  • What do you mean by actual text? Commented Jul 18, 2011 at 1:38
  • Instead of an actual linebreak, have it actually output the characters "\n" for example... Commented Jul 18, 2011 at 1:38

4 Answers 4

5
echo str_replace(array("\n", "\r"), array('\n', '\r'), $input);
Sign up to request clarification or add additional context in comments.

Comments

1

Escape them before printing.

echo '\\r\\n';

Comments

0

Did you try escaping your slashes with another slash?

Comments

0

Try

$string = str_replace(array("\r", "\n"), array('\r', '\n'), $string);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.