PHP Output Buffering
<HTML> <HEAD> <TITLE> something special </TITLE> </HEAD> <BODY> … # 1 - Need to capture this output! // output producing code // output need to be captured # 2 … </BODY> </HTML>
One very important use of Output Buffering is with compressing the data before sent to user. PHP has inbuilt function ob_gzhandler which can be used with PHP Output Buffering function as a callback function. Combination of Output Buffering function and this ob_gzhandler function can do the wonder, as this will reduce the size of output (response) to the client (user/browser).
One another handy trick you can use is when you want to discard some output. When this case can arise? Suppose you are in charge of debugging a php page. There you have found lots of files are included (using require/include/..) and that are giving lots of warning Notice messages. This is so because now you have set the error_reporting(E_ALL). Now you can suppress the E_NOTICE and E_WARNING message by using error_reporting(E_ALL ^ E_NOTICE). But suppose you want to see all errors of your modified code. Then? Output Buffering can help you here too.
Possibly Related posts:


Output Buffering can get you part of the output to process for string manipulation before sending the output to user. And what it means?
Suppose you have this page: