我正在尝试从Robin Nixon的"学习php MySQL和Javascript"中学习php.
在其中,他解释了下面的代码应该如何按字面输出(带有行结尾和空格).但它在一条线上输出所有东西.这是为什么?
$author = "Alfred E Newman";
echo <<<_END
This is a headline
This is the first line
This is the second
- Written by $author.
_END;
Run Code Online (Sandbox Code Playgroud)
它很可能是输出"自有行"上的所有内容,但是,如果这是在HTML页面上,则可能无法保留换行符.包裹所有内容<pre>以保留所有空白区域.
例:
echo <<<_END
<pre>
This is a headline
This is the first line
This is the second
- Written by $author.
</pre>
_END;
Run Code Online (Sandbox Code Playgroud)
要进行适当的标记,您应该将元素包装在各自的容器中,例如:
echo <<<_END
<h2>This is a headline</h2>
<p>This is the first line</p>
<p>This is the second</p>
<p>- Written by $author.</p>
_END;
Run Code Online (Sandbox Code Playgroud)
上面的示例将您的内容分解为多个部分.