They both seem to do the same thing: return the output buffer content to you and delete it aftewards.
Which one should I use?
The ob_get_clean() function returns the contents of the output buffer and then deletes the contents from the buffer.
The ob_start() function creates an output buffer. A callback function can be passed in to do processing on the contents of the buffer before it gets flushed from the buffer. Flags can be used to permit or restrict what the buffer is able to do.
Output buffering is a mechanism for controlling how much output data (excluding headers and cookies) PHP should keep internally before pushing that data to the client. If your application's output exceeds this setting, PHP will send that data in chunks of roughly the size you specify.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With