php echo inside $output


php echo inside $output

我正试图从页面中获取特定的页面内容,我需要插入以下php代码:

我试过这个:

$output .= <<<HTML
            </div>
        </div>
<div id="hometabs">
echo getPageContent(8);
    </div>
<div class="clear"></div>
    </div>
    <div class="bottom_shadow"></div>
</div>
HTML;

但它不起作用。。我甚至试过:

getPageContent(8);
echo getPageContent(8)
<?php echo getPageContent(8);?>

但它没有

注意:我已经有了getPageContent的代码,我只是不确定为什么在浏览器上查看时,会出现以下代码:echo getPageContent(8)而不是执行它。

您使用的语法在PHP中被称为Heredoc。这是一种构建字符串并将其放入变量的特殊方式,但它允许您使用换行符、引号和其他很酷的东西(比如在字符串中使用php变量)。

不幸的是,除非对代码进行一些特殊而有创意的语法更改,否则无法在heredoc中执行函数。这是另一个类似于您所面临的SO问题:在HEREDOC字符串中调用PHP函数。

如果我这样做,我可能会把语法改成这样(看看这是否适用于你):

$the_content = getPageContent(8);
$output .= <<<HTML
        </div>
    </div>
    <div id="hometabs">
        $the_content
    </div>
    <div class="clear"></div>
    </div>
    <div class="bottom_shadow"></div>
    </div>
HTML;