php ob_clean 和 ob_flush 的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8770910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between ob_clean and ob_flush?
提问by Alex V
What's the difference between ob_clean()
and ob_flush()
?
ob_clean()
和 和有ob_flush()
什么区别?
Also what's the difference between ob_end_clean()
and ob_end_flush()
? I know ob_get_clean()
and ob_get_flush()
both get the contents and end output buffering.
还什么之间的区别ob_end_clean()
和ob_end_flush()
?我知道ob_get_clean()
并且ob_get_flush()
都得到内容并结束输出缓冲。
回答by Adam Wagner
the *_clean
variants just empty the buffer, whereas *_flush
functions print what is in the buffer (send the contents to the output buffer).
该*_clean
变种刚清空缓冲区,而*_flush
功能打印的内容是在缓冲区(发送内容到输出缓冲)。
Example:
例子:
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)
回答by Arun Gangula
The key difference is
*_clean()
discards changes and *_flush()
outputs to the browser.
关键的区别是
*_clean()
丢弃更改并*_flush()
输出到浏览器。
Usage of ob_end_clean()
的用法 ob_end_clean()
it is mostly used when you want to have a chunk of html and do not want to output to the browser right away but may be used in future.
它主要用于当您想要一大块 html 并且不想立即输出到浏览器但可能在将来使用时。
Eg.
例如。
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);
where as ob_end_flush()
will render twice, once for each.
asob_end_flush()
将渲染两次,每个渲染一次。