php heredoc出错

时间:2013-02-25 04:48:01

标签: php heredoc

我有一个php heredoc的问题。我正试图做这样的事情。

$heredoc = <<<_HERE
This is the way
I try to use the
heredoc, but apparently
something is going wrong
_HERE;

显然我应该得到这个:

This is the way
I try to use the
heredoc, but apparently
something is going wrong

但我明白了:

这是我尝试使用heredoc的方式,但显然出现了问题

它没有格式化,主要思想是获取格式化文本。

有人能帮助我吗?

2 个答案:

答案 0 :(得分:2)

使用预标签:

$heredoc = <<<_HERE
<pre>
This is the way
I try to use the
heredoc, but apparently
something is going wrong
</pre>
_HERE;

答案 1 :(得分:0)

尝试

<?php
    $heredoc = <<<_HERE
This is the way
I try to use the
heredoc, but apparently
something is going wrong
_HERE;

    echo "<pre>";
    echo $heredoc;
    echo "</pre>";
?>