PHP - print string with control characters

后端 未结 4 668
难免孤独
难免孤独 2021-01-28 10:09

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\'

相关标签:
4条回答
  • 2021-01-28 10:52

    Escape them before printing.

    echo '\\r\\n';
    
    0 讨论(0)
  • 2021-01-28 10:52

    Try

    $string = str_replace(array("\r", "\n"), array('\r', '\n'), $string);
    
    0 讨论(0)
  • 2021-01-28 10:58
    echo str_replace(array("\n", "\r"), array('\n', '\r'), $input);
    
    0 讨论(0)
  • 2021-01-28 11:14

    Did you try escaping your slashes with another slash?

    0 讨论(0)
提交回复
热议问题