PHP ob gzhandler:php OB

Source: Internet
Author: User


The
output control function gives you free rein to the data in the script. It's very useful, especially for: when you want to


after the data has been exported, the file header is then output. The output control function does not use header () or Setcookie (),

The header information sent by
affects only those blocks of data that resemble the Echo () and PHP code.


let us give a simple example to give you a general impression of output control:


Example 1.


-------------------------------------------------------------------------------------


---------------------------------


Ob_start (); Open Buffer


echo "hello\n"; Output


header ("location:index.php"); redirect browser to index.php


Ob_end_flush ()//output all content to browser


?>


-------------------------------------------------------------------------------------


---------------------------------


all people who know about the header () function know that this function sends a file header to the browser, but if you are using the


This function already has any output (including null output, such as a space, carriage return, and linefeed) that prompts for an error. If I


get rid of the first line of Ob_start (), and then execute the program, we'll find an error message: "Header had


All ready send by "! But with Ob_start, you won't be prompted for an error, because when the buffer is open, the echo behind


characters are not exported to the browser, but are kept on the server until you use flush or ob_end_flush to output,


to not have any file header output error!


one, related function introduction:


1, Flush: Refresh the contents of the buffer, output.


function Format: Flush ()


Note: This function is often used, high efficiency.


2, Ob_start: Open Output Buffer


function format: void Ob_start (void)


Note: When the buffer is activated, all non-file header information from the PHP program is not sent, but is saved in the internal buffer.


to output the contents of the buffer, you can use Ob_end_flush () or flush () to output the contents of the buffer.


3, Ob_get_contents: Returns the contents of the internal buffer.


Use Method: String ob_get_contents (void)


Description: This function returns the contents of the current buffer, false if the output buffer is not active.


4, Ob_get_length: Returns the length of the internal buffer.


use method: int ob_get_length (void)


Description: This function returns the length of the current buffer, as with ob_get_contents, if the output buffer is not excited


Live. returns FALSE.


5, Ob_end_flush: Sends the contents of the internal buffer to the browser and closes the output buffer. This article links http://www.cxybl.com/html/wlbc/Php/20120531/27127.html





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.