duanshan5259 2015-07-13 18:34
浏览 230
已采纳

如何输出一个字符串,其中的换行符在php中可见?

I have a string with newlines that I'd like to print out so that I see the special chars (such as ) rather than the newlines themselves.

So a string that would typically be echo'd as

this is the top line of my string
this is the second line of the string

Would instead look like this:

this is the top line of my string
this is the second line of the string

How could I accomplish this in php?

  • 写回答

3条回答 默认 最新

  • dth34653 2015-07-13 18:45
    关注

    Try this:

    <?php
    
    $string = "this is the top line of my string
    this is the second line of the string";
    
    echo json_encode($string);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?