PHP Output Buffering

Output buffering in PHP is useful in many cases. At many places it can be a handy tool. One example use of 'Output Buffering' is to stop the "header already sent" problem. It can help your user to get the response fast. It means decrease the waiting time for your reader.
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:
<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>
Now, you want to capture the content between 1# and #2 for some reason, say searching something in it. This data may be the data coming from outside (database/xml and others) and that is just a function and that function, instead of returning you value, directly echo-ing/printing the data. PHP Output buffer can help you.

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.