Skip to content

Instantly share code, notes, and snippets.

@junaidtk
Created March 15, 2019 06:15
Show Gist options
  • Save junaidtk/d3bd838351dc3351fa51ff7e5312fa9e to your computer and use it in GitHub Desktop.
Save junaidtk/d3bd838351dc3351fa51ff7e5312fa9e to your computer and use it in GitHub Desktop.
Use of ob_start() and ob_get_clean()
The ob_start() and ob_get_clean() are used hold the value in the inter buffer memory.
Normal Buffering functions used are.
ob_start();
---------------
This function will turn on the out buffer While buffering is ON no output is sent from script (other then headers),
instead the output is stored in internal buffer.
ob_get_clean();
------------------
Gets the current output buffer content and delete current output buffer.
Returns the contents of the output buffer and end output buffering. If output buffering isn’t active then FALSE is returned.
Ob_get_clean() executes both ob_get_contents() and ob_end_clean().
ob_end_flush();
------------------
Ends the buffer and sends all data to output.
ob_end_clean();
------------------
Ends the buffer without sending it to output.
Eg:
ob_start();
print “Hello First!\n”;
ob_end_flush();
It will print " Hello First "
ob_start();
print “Hello Second!\n”;
ob_end_clean();
It wont print anything.
ob_start();
echo 'Helloo';
$out = ob_get_clean();
It won't print anything, It will return data to $out variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment