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;
?>
結果は複数行です。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;
このように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;
?>