Scroll to top

How to use ob_start() function in php?

PHP | ob_start() Function

PHP is an interpreted language thus each statement is executed one after another, therefore PHP tends to send HTML to browsers in chunks thus reducing performance. Using output buffering the generated HTML gets stored in a buffer or a string variable and is sent to the buffer to render after the execution of the last statement in the PHP script.
But Output Buffering is not enabled by default. In order to enable the Output Buffering one must use the ob_start() function before any echoing any HTML content in a script.

function jassi
{
ob_start();
echo “Hello there!”;
$output = ob_get_contents();
ob_end_clean();
}

OR

function jassi
{
ob_start();
echo “Hello there!”;
$obc = ob_get_contents();
ob_end_clean();
return $obc;
}

Leave a Reply

Your email address will not be published. Required fields are marked *