PHP heredoc不接受换行


PHP heredoc does not take linefeed

当我尝试在PHP中测试heredoc构造时,我遇到了一个谜。我不知道这个代码有什么问题:

<?php
$author = "Scott Adams";
$out = <<<_END
Normal people believe that if it ain't broke, don't fix it.      
Engineers believe that if it ain't broke, it doesn't have enough
features yet.
- $author.
_END;
echo  $out;
?>

根据我的书,这里没有必要使用换行符,只需键入回车键即可。但它不需要linefeed,只需打印文本即可。我的apache服务器有问题吗?或者可能配置错误?我使用的是默认设置。

谢谢你的帮助。

在浏览器中,所有空白(制表符、新行、多个空格)都被折叠。

如果你想在浏览器中显示新行,你需要添加html换行符:

echo nl2br($out);