我试图像这样打印一个新行。但它不起作用。然后我尝试用PHP_EOL
打印它但没有运气。这是为什么。我的PHP版本是5.6和XAMPP。我在Windows 8.1上运行。这是我的代码
<?php
echo "Add a new line \n Add a second new line";
?>
显示输出为
添加新行添加第二个新行
我想知道为什么不工作
答案 0 :(得分:2)
\ n尝试:
<?php
echo nl2br("Add a new line \n Add a second new line");
?>
答案 1 :(得分:0)
尝试以下代码:您的网页内容类型问题
<?php
header('Content-type: text/plain');
echo "Add a new line \n Add a second new line";
?>
答案 2 :(得分:0)
如果您想在网页上添加新行,则应使用
在文件中写入数据时,请使用PHP_EOL或\ n,\ r,\ n \ r
来自php manual:
// Outputs: This will not expand: \n a newline
echo 'This will not expand: \n a newline';
// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';