The OutputControl function allows you to control the output of data in the script. It is very useful, especially when you want to output the file header after the data has been output. The Output Control function does not use header () or setcookie (). the Output Control function generates the file header information to allow you to Control the data Output in the script. It is very useful, especially when you want to output the file header after the data has been output. The output control function does not affect the header information sent using header () or setcookie (). it only applies to data blocks similar to echo () and PHP code.
Let's take a simple example to give you a general impression on Output Control:
Example 1.
Bytes -----------------------------------------------------------------------------------------------------------
Ob_start (); // open the buffer Echo "Hello \ n"; // output Header ("location: index. php"); // redirects the browser to index. php. Ob_end_flush (); // output all content to the browser ?> |
Bytes -----------------------------------------------------------------------------------------------------------
Anyone who knows about the header () function knows that this function will send a file header to the browser, but if any output (including null output, for example, a blank space, carriage return, or line feed will prompt an error. If we remove ob_start () from the first line and execute this program, we will find an error message: "Header had all ready send "! However, when ob_start is added, no error will be prompted because when the buffer zone is opened, the characters after echo will not be output to the browser, but will be retained on the server until you use flush or ob_end_flush, so there will be no file header output errors!