开发者

PHP - print string with control characters

开发者 https://www.devze.com 2023-03-20 18:56 出处:网络
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 runn

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

精彩评论

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

关注公众号