可能重复:
Have I misunderstood what heredoc should do?为什么所有文本都打印在同一行上?
,我读了这里记录保留行文本打破 和其他空白(包括缩进)。但是当我运行下面的脚本时,所有东西都打印在同一行上。为什么这样?
<?php
$str = <<<HDC
This is a sample text
Some more sample text
Even more sample text
HDC;
echo $str;
可能重复:
Have I misunderstood what heredoc should do?为什么所有文本都打印在同一行上?
,我读了这里记录保留行文本打破 和其他空白(包括缩进)。但是当我运行下面的脚本时,所有东西都打印在同一行上。为什么这样?
<?php
$str = <<<HDC
This is a sample text
Some more sample text
Even more sample text
HDC;
echo $str;
输出实际上包含换行符。但是,HTML(默认情况下)会忽略换行符。
如果你想在HTML渲染换行符,在pre
包装它:
<pre>
<?php
$str = <<<HDC
This is a sample text
Some more sample text
Even more sample text
HDC;
echo $str;
?>
</pre>
或者,如果你不能使用<pre>
因为<pre>
总是在固定宽度打印,手动插入<br>
标签。
_”或者如果你不能使用,因为总是以固定宽度打印...“_这是什么意思? – saplingPro
我认为@saplingPro知道'
'标签。他只是想完全打理'heredoc's。我对吗? –
@JosephSilber是啊:) – saplingPro
其工作。 “http://codepad.org/h2jSMZZY –