Scroll to top

How to use ob_start() function in php?


Notice: Undefined variable: string in /home/u665484253/domains/wpcodekit.com/public_html/wp-content/themes/twentytwenty-child/functions.php on line 61

 

PHP | ob_start() Function

  1. output buffering
  2. function jassi
  3. echo hello
  4. = ob_get_contents
  5. php
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;
}

Get more information

Read More Posts

Leave a Reply

Your email address will not be published.