0

htmlページのこのコードは1行で表示されます。バックスラッシュ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 に答える