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 send
The Output Control function allows you to Control the Output of data in the script. It is very useful, especially when you want
Output the file header after the data has been output. The output control function does not apply header () or setcookie (),
The file header information sent has an impact on data blocks that are similar to echo () and PHP code.
Let's take a simple example to give you a general impression on Output Control:
Example 1.
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
?>
Anyone who knows the header () function knows that this function will send a file header to the browser.
If this function already has any output (including empty output, such as space, carriage return, and line feed), an error will be prompted. Assume that I
We dropped the ob_start () in the first line and then executed 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
Will not be output to the browser, but will be retained on the server until you apply flush or ob_end_flush.
So there will be no file header output errors!
1. Introduction to coherent functions:
1. Flush: refresh the buffer content and output it.
Function pattern: flush ()
Clarification: This function is often used and highly efficient.
2. ob_start: Open the output buffer.
Function pattern: void ob_start (void)
Note: When the buffer zone is activated, all non-file header information from the PHP program is not sent, but is kept in the internal buffer zone.
To output the buffer content, you can apply ob_end_flush () or flush () to output the buffer content.
3. ob_get_contents: returns the content of the internal buffer.
Application method: string ob_get_contents (void)
Clarification: This function returns the content in the current buffer. if the output buffer is not activated, FALSE is returned.
4. ob_get_length: return the length of the internal buffer.
Application method: int ob_get_length (void)
Clarify: This function will return the length of the current buffer; same as ob_get_contents, if the output buffer is not excited
Active. Returns FALSE.
5. ob_end_flush: sends the content of the internal buffer to the browser and closes the output buffer.
Application method: void ob_end_flush (void)
Clarify: This function sends the content of the output buffer (if any ).