在html页面上,如何让PHP使用多行?

时间:2012-06-21 17:21:58

标签: php html

html页面上的此代码以一行形式出现。为什么反斜杠没有工作?

    <?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;
    ?>

2 个答案:

答案 0 :(得分: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;

答案 1 :(得分: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;
    ?>