The Function Ob_Get_Contents() in PHP
PHP is the OG of web programming and is still the backbone of WordPress, which alone powers 25% of the web. While all the hype is around JavaScript this and HTML5 that it is easy to forget about how cool PHP really is.
One of the things that makes it so cool is its ability to utilize output buffering. This allows the engine to process the data and then send it as it is ready. This is important because it prevents the browser from receiving the output in pieces and can save a lot of time.
The function ob_get_contents() retrieves the content stored in the topmost buffer. This information is useful because you can use it to manipulate the output before it is sent to the browser. This is a great way to ensure that the output sent matches what was compiled in your script.
This function also allows you to clear and flush all of the output buffers. It is recommended that you only use this when needed and only on the root level of the output buffering process. If you call it on a child function level it will not clear the contents of that buffer but will instead empty the parent buffer and turn off output buffering at that level.
Output buffering is a great tool in PHP for making sure that your output is exactly as you intend it to be. There are a number of functions that help make it easy to control the content and how it is sent to the browser.