Output Buffering is a method to tell the PHP engine to hold the output data before sending it to the browser. As we know PHP sent the output data to the browser in pieces, but if we utilize the output buffering mechanism, the output data is stored in a variable and sent to the browser as one piece at the end of the script.
Let's demonstrate with a simple example.
<?php ob_start(); echo "Hello"; $ob1 = ob_get_contents(); echo "Tutorials Point"; $ob2 = ob_get_contents(); ob_end_clean(); var_dump($ob1, $ob2); ?>
string(5) "Hello" string(20) "HelloTutorials Point"
In the above example ob_get_contents() grabs all of the data gathered since we called ob_start, i.e. everything in the buffer. After that send the output data at once.