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;
?>
结果是多行的。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;
?>