PHP | ob_end_flush(), ob_end_clean() Functions Last Updated : 08 Mar, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 // 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: ob_end_flush() or ob_end_clean() are not necessary functions i.e. if a developer ever uses ob_start() without using the mentioned functions the webpage will appear to be working correctly displaying every content, but what happens in the back is nowhere near optimized. When PHP encounters ob_start() it allocates a new output buffer and concatenates every HTML that appears after it, if there is no terminating function then upon reaching the end the stored data is sent to the browser as a default action. Developers can create optimized web pages by terminating the output buffering when not required thus keeping the global stack clear. There raises a question, if we use ob_end_clean() to clean the whole output buffer then why even use output buffering. We use ob_end_clean() with ob_get_contents() which first gets the contents as a string and then the output buffer is cleaned and turned off, this clears the global stack and keeps the whole content in a variable to be processed further. Reference: https://www.php.net/manual/en/function.ob-end-flush.php https://www.php.net/manual/en/function.ob-end-clean.php Comment More infoAdvertise with us Next Article PHP | DsStack clear() Function P PronabM Follow Improve Article Tags : Misc Web Technologies PHP PHP-output PHP-function +1 More Practice Tags : Misc Similar Reads PHP ob_get_clean() Function The ob_get_clean() function is an in-built PHP function that is used to clean or delete the current output buffer. It's also used to get the output buffering again after cleaning the buffer. The ob_get_clean() function is the combination of both ob_get_contents() and ob_end_clean(). Syntax: string|f 2 min read PHP ob_get_contents() Function The ob_get_contents() is an inbuilt function in PHP that is used to capture what is currently being buffered by the output buffer. This function returns the output buffer. Syntaxob_get_contents(): string | falseParameter This function does not accept any parameters. Return Value The ob_get_contents( 2 min read PHP DsQueue clear() Function The Ds\Queue::clear() Function in PHP is used to clear all of the elements from a Queue instance. This function just clears the instance without deleting it. Syntax: void public Ds\Queue::clear ( void ) Parameters: This function does not accepts any parameters. Return Value: This function does not r 1 min read PHP | DsDeque clear() Function The Ds\Deque::clear() function is an inbuilt function in PHP which is used to clear the Deque by removing all elements from the Deque. Syntax: public Ds\Deque::clear( void ) : void Parameters: This function does not accepts any parameter. Return Value: This function does not return any Value. Below 2 min read PHP | DsStack clear() Function The Ds\Stack::clear() function of PHP is used to remove all elements from a Stack and clear it. This function simply removes all of the elements from the Stack but not completely deletes it. It just empties it. Syntax: void public Ds\Stack::clear ( void ) Parameters: This function does not accept an 2 min read PHP | startsWith() and endsWith() Functions startsWith() Function The StartsWith() function is used to test whether a string begins with the given string or not. This function is case insensitive and it returns boolean value. This function can be used with Filter function to search the data. Syntax bool startsWith( string, startString ) Param 3 min read Like