<html>
<body>
<?php startblock("content"); ?>
<p> Page content </p>
<?php endblock("content"); ?>
</body>
</html>
我想获取两个php函数之间的内容。如果你看一下上面的例子,我想在字符串中得到“<p> page content <p>
”。
提前完成
答案 0 :(得分:2)
您可以使用Output Buffering
<html>
<body>
<?php ob_start(); ?>
<p> Page content </p>
<?php $html = ob_get_clean(); ?>
</body>
</html>
答案 1 :(得分:1)
声明这样的函数:
function startblock()
{
ob_start();
}
function endblock()
{
$content = ob_get_flush();
return '+++' . $content . '+++';
}
请注意,您无法嵌套此内容。据我所知,你不能有多个具有名称的输出缓冲区。因此,您添加的参数没有用处。