0

html 页面上的这段代码是一行。为什么反斜杠 n 不起作用?

    <?php
        $text1 =  "I don't understand how this works!  \nHow the hell do I get this thing to use \nmulti lines in PHP???!!!";
        echo $text1;
    ?>
4

2 回答 2

5

结果是多行的。HTML 只是忽略换行符(请参阅页面的源代码以查看它)。您可能想<br>在 HTML 中使用换行符。

<?php
$text_to_echo =
    "I don't understand how this works!<br>\n
How the hell do I get this thing to use <br>\n
multi lines in PHP???!!!";
echo $text_to_echo;
于 2012-06-21T17:23:24.563 回答
0

像这样使用nl2br()函数。

<?php
        $text1 =  nl2br("I don't understand how this works!  \nHow the hell do I get this thing to use \nmulti lines in PHP???!!!");
        echo $text1;
    ?>
于 2012-06-21T17:31:46.007 回答