PHP ob_start() FunctionOb _ start function is used to create an output buffer in PHP, as we are already aware that PHP is an interpreted language, i.e. any program written in PHP will be executed stepwise, one statement after another, which makes processing comparatively slow compared to others. Therefore, PHP uses the ob_start() function, which creates an output buffering that stores generate HTML inside a cluster/buffer or a string variable that is later sent to render, thus increasing speed and reducing execution time. In order to execute the output buffer, we have to use the ob_start () function, which uses a callback function that is used to process the contents of the buffer. The function will return TRUE on successful transmission and FALSE on failure Syntax:
Example 1:Output: Here in this program, we have used OB _ START ( ) function to create the output buffer, and the OB _ END _ CLEAN ( ) function will be used to clear all the data of the created buffer; therefore, only the text outside the B _ START ( ) function and OB _ END _ CLEAN ( ) function will be displayed. Example 2:Output: here in this program, first, we have declared the CALL BACK ( ) function with variable $firstbuffer. The property of this function is to return everything written inside as capital. We have used OB _ START ( ) function to create an output buffer with parameters as call back to initiate the function. Due to the call function, all the text after OB _ START ( ) will be displayed in caps. Example 3:Output: As we know, a buffer stores the data in a string variable. We can use all the properties of strigs. Here in this program, first, we have declared the CALL BACK ( ) function with variable $mybuffer. The property of this function is to replace a declared string with another. We have used the OB _ START ( ) function to create an output buffer with the parameter call back to initiate the function. Due to the call function, all the b after OB _ START ( ) will be converted to * * *. Next TopicPHP Beautifier |