PHP | ob_start() Function Last Updated : 08 Mar, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report Let's take a quick recap. 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. Syntax: bool ob_start () Parameters: The function can accept a bunch of optional parameters as follows: Callback function: This is an optional parameter that expects a function that takes the contents of the output buffer and returns a string that is to be sent to the browser for rendering. The callback function is generally used for compressing the HTML content. Chunk size: This is another optional parameter that sets the output buffer size of provided size and outputs as soon as the buffer is either full or exceeded. Flags: This is another optional parameter that accepts a bitmask to control the operations that can be implemented on the output buffer. This parameter is passed to restrict access. The Default permissions gives access to clean, flush and removal of the buffer. Return Type: This function returns TRUE on success otherwise FALSE. Below program illustrates the working of ob_start() in PHP: PHP <?php // PHP code to illustrate the working // of ob_start() Function function callback($buffer){ // Return Everything in CAPS. return (strtoupper($buffer)); } ob_start("callback"); echo "Hello Geek!"; ob_end_flush(); ?> Output: HELLO GEEK! Important points to note: Enables Output Buffering. Output Buffering flags can be of four types PHP_OUTPUT_HANDLER_CLEANABLE(only clean), PHP_OUTPUT_HANDLER_FLUSHABLE(only flush), PHP_OUTPUT_HANDLER_REMOVABLE(only remove), PHP_OUTPUT_HANDLER_STDFLAGS(allowed every operation). Output buffers are stackable, thus nested ob_start() methods are allowed and works as desired if they are closed/flushed sequentially. Reference: https://www.php.net/manual/en/function.ob-start.php Comment More infoAdvertise with us Next Article PHP mb_strstr() Function P PronabM Follow Improve Article Tags : Misc Web Technologies PHP PHP-input-output PHP-function +1 More Practice Tags : Misc Similar Reads PHP mb_strstr() Function The mb_strstr() function is an inbuilt function in PHP that finds the first occurrence of a given string in the main string, i.e. it will search for the occurrence of the first needle in haystack, & id found then the portion of the haystack will be returned, otherwise return false. Syntax: mb_st 2 min read PHP ob_get_status() Function The ob_get_status() is an inbuilt function in PHP that is used for retrieving the status of the output buffer. Syntaxob_get_status(bool $full_status = false) : arrayParameter This function accepts only one parameter which is described below. $full_status: This is an optional parameter. If this param 2 min read PHP mb_strrichr() Function The mb_strrichr() function is a case-insensitive in-built function. This function searches a multi-byte string for the last occurrence of a specified character and returns the portion of the string. Syntax: mb_strrichr( $haystack, $needle, $before_needle , $encoding) : string|falseParameters:Â This f 2 min read PHP pos() Function The pos() is an inbuilt function in PHP which is used to return the value of the element in an array which the internal pointer is currently pointing to. The pos() function does not increment or decrement the internal pointer after returning the value. In PHP all arrays have an internal pointer. Thi 2 min read PHP prev() Function The prev() function is an inbuilt function in PHP. It is used to return the immediate previous element from an array of the element which is currently pointed by the internal pointer. We have already discussed current() function in PHP. The current() function is used to return the value of the eleme 2 min read PHP | print_r() Function The print_r() function is a built-in function in PHP and is used to print or display information stored in a variable. Syntax: print_r( $variable, $isStore ) Parameters: This function accepts two parameters as shown in above syntax and described below. $variable: This parameter specifies the variabl 2 min read Like