Difference between ob_get_clean and ob_get_flush

孤者浪人 提交于 2019-12-03 05:30:31

问题


They both seem to do the same thing: return the output buffer content to you and delete it aftewards.

Which one should I use?


回答1:


To directly try to answer your question:

If you wish to begin output buffering again after flushing the buffer, then use ob_get_clean as output buffering will still be ready without having turn it back on. (remember this can only be used if no text, even whitespace is echo'd to the browser). Thus for more general uses, all my programming books err towards ob_get_flush (as only one buffer per most scripts)




回答2:


ob_get_clean() removes the buffer (without printing it), and returns its content.

ob_get_flush() prints the buffer, removes it, and returns its content.

Both function will terminate the buffer.




回答3:


ob_get_clean will just return the contents of the buffer and assign it to whatever variable you want it to, but it will not output anything.

ob_get_flush on the other hand, does everything that ob_get_clean does, but it also outputs the content.




回答4:


Both functions clear the output buffer, turn off output buffering, and return the previous buffer value.

However, ob_get_flush first sends the current buffer to the client, whereas ob_get_clean just discards it.



来源:https://stackoverflow.com/questions/7379735/difference-between-ob-get-clean-and-ob-get-flush

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!