These output control functions include ob_start(0, ob_clean(),ob_get_contents(), etc. To be honest, I am always mess up these ob_xxx() functions, some of them have similar functions and some of them can be substituted with some combinations of other functions. Today I reviewed these functions again. I tried to find the relationship among different ob_xxx() functions. Here is what I have now.
ob_clean() : It discards the contents of the output buffer but will not destroy the output buffer. My understanding is that the output buffer contents are cleared but the memory allocated is not freed. It can be used when before calling header() functions.
ob_end_clean() : It is similar to ob_clean(), the differences are:
- It discards the contents of the topmost output buffer
- It will free up the memory allocated to the output buffer.
ob_get_flush() : It is similar to ob_end_flush(), but it will return the buffered output as a string instead of echoing them to the client. It can be described as ob_end_clean()+(return buffered output string)
ob_flush() : Send the contents of the output buffer to the client.
ob_get_contents() : Return the output buffer as a string and don't clear the output buffer.
ob_get_clean() : It is ob_get_contents()+ob_end_clean();
Other ob_xxx() functions are not so confusing, so I don't describe them here. You can check the PHP Output Buffer Control manual to read the details and some examples there are also very helpful.
The above summary may not be very accurate, they are my understanding about the output control functions in PHP. If you find any mistakes I made, please correct it for me. Thank you.