开发者

PHP - print string with control characters

Is there any way to have PHP output a string with the \r\n and \n's as actual te开发者_如何学JAVAxt 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...


echo str_replace(array("\n", "\r"), array('\n', '\r'), $input);


Escape them before printing.

echo '\\r\\n';


Did you try escaping your slashes with another slash?


Try

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜