Open In App

PHP | ob_end_flush(), ob_end_clean() Functions

In the previous article on ob_start(), we learned how to start the output buffer; now we need to end the output buffering and send the whole HTML to the browser to render. We can do this by the help of functions ob_end_flush() and ob_end_clean().

ob_end_flush() Function



Syntax:

bool ob_end_flush ()

Parameters: The function doesn’t take any parameter.



Return Type: This function sends the HTML stored to browser and turns off output buffering. On success, TRUE is returned otherwise FALSE.

ob_end_clean() Function

Syntax:

bool ob_end_clean()

Parameters: The function doesn’t take any parameter.

Return Type: This function cleans the HTML stored and turns off output buffering. On success, TRUE is returned otherwise FALSE.

Below program illustrates the working of ob_end_flush() and ob_end_clean() in PHP:




<?php
  
// PHP code to illustrate the working of 
// ob_end_flush() and ob_end_clean()
  
// ob_end_flush()
ob_start();
echo "Hello Geek!"; //This will get printed.
ob_end_flush();
  
// ob_end_clean() 
ob_start();
echo "Hi Geek!"//This will not get printed.
ob_end_clean();
  
?>

Output:

Hello Geek!

Important points to note:

Reference:

Article Tags :