ob_clean()
和 ob_flush()
有什么区别?
此外,ob_end_clean()
和 ob_end_flush()
有什么区别?我知道 ob_get_clean()
和 ob_get_flush()
都是获取缓冲区内容并结束输出缓冲。
ob_clean()
和 ob_flush()
有什么区别?
此外,ob_end_clean()
和 ob_end_flush()
有什么区别?我知道 ob_get_clean()
和 ob_get_flush()
都是获取缓冲区内容并结束输出缓冲。
*_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)
ob_end_clean()
的意思就是丢弃缓冲区中的所有内容。 - Pacerier关键区别在于*_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()
会渲染两次,每个都渲染一次。
ob_clean()
、ob_flush()
、ob_end_clean()
和ob_end_flush()
的手册页面,或者解释需要详细说明的特定方面。 - marioprint
或echo
一样),因此您在函数签名中看不到任何区别。 - Adam Wagner