这里需要一些 PHP 帮助,包含的内容显示为“1”,这意味着它是真实的,但需要它的内容才能显示,我不确定为什么不是。这是一个函数的简化版本:
public function content {
$website->content = 'Some content here. ';
ob_start();
include('myfile.php');
$file_content = ob_end_clean();
$website->content .= $file_content;
$website->content .= ' Some more content here.';
echo $website->content;
}
这个输出:
Some content here 1 Some more content here
当我需要它输出时:
Some content here 'Included file content here' Some more content here
知道如何解决这个问题吗?
最佳答案
尝试使用 ob_get_clean()
而不是 ob_end_clean()
。
两者都清除当前缓冲区,但 ob_end_clean()
返回一个 bool 值,而 ob_get_clean()
返回当前缓冲区的内容。
关于php - 在 ob_start() 中使用 include(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8510532/