ob_clean()
和ob_flush()
之间有什么区别?
ob_end_clean()
和ob_end_flush()
之间有什么区别?我知道ob_get_clean()
和ob_get_flush()
都获取内容和结束输出缓冲。
答案 0 :(得分:50)
*_clean
变体只清空缓冲区,而*_flush
函数打印缓冲区中的内容(将内容发送到输出缓冲区)。
ob_start();
print "foo"; // This never prints because ob_end_clean just empties
ob_end_clean(); // the buffer and never prints or returns anything.
ob_start();
print "bar"; // This IS printed, but just not right here.
ob_end_flush(); // It's printed here, because ob_end_flush "prints" what's in
// the buffer, rather than returning it
// (unlike the ob_get_* functions)
答案 1 :(得分:0)
关键区别是
*_clean()
放弃更改,而*_flush()
输出到浏览器。
使用ob_end_clean()
它通常用于想要拥有大量html且不希望立即输出到浏览器的情况,但将来可能会使用。
例如。
ob_start()
echo "<some html chunk>";
$htmlIntermediateData = ob_get_contents();
ob_end_clean();
{{some more business logic}}
ob_start();
echo "<some html chunk>";
$someMoreCode = ob_get_content();
ob_end_clean();
renderTogether($htmlIntermediateCode, $someMoreCode);
其中ob_end_flush()
将呈现两次,每个呈现一次。