PHP output control functions and output functions generate static pages

Source: Internet
Author: User
Tags flushes

The Output Control function is detailed:
  • flush-Refresh the output buffer
  • ob_clean-Empty the output buffer
  • ob_end_clean-Clears the buffer and turns off the output buffer
  • ob_end_flush-Flushes out the output buffer contents and closes the buffer
  • ob_flush-Flushes out the contents of the output buffer
  • ob_get_clean-Gets the contents of the current buffer and deletes the current output cache
  • ob_get_contents-Returns the contents of the output buffer
  • ob_get_flush-Brush out buffer contents, return content as a string, and close the output buffer
  • ob_get_length-Returns the length of the output buffer content
  • ob_get_level-Returns the nesting level of the output buffering mechanism
  • ob_get_status-Get the status of all output buffers
  • ob_gzhangdler- ob_start中 callback function used to compress the contents of the output buffer
  • ob_implicit_flush-Turn absolute swipe on/off
  • ob_list_handlers-List all the output handlers in use
  • ob_start-Open Output Control buffer
  • output_add_rewrite_var-Add the value of the URL rewrite
  • output_reset_rewrite_vars-Resets the value of the URL rewrite
General description of output control functions : ob_start

This function opens the output buffer. When the output buffer is activated, the script will not output content (except for the HTTP header), and the output will be stored in the internal buffer instead.

The contents of the internal buffer can be ob_get_contents() copied into a string variable using a function.
To output content stored in an internal buffer, you can use a ob_end_flush() function. In addition, ob_end_clean() the use of functions silently discards the contents of the buffer.

The output buffers are stackable , which means that when there is one that ob_start() is active, you can invoke the other ob_start() .
Just make sure that the ob_end_flush() appropriate number of times is called correctly. If multiple output callback functions are active, the output will be filtered sequentially through them in nested order.

flush

Refreshes the PHP program's buffering, which sends all the output of the program so far to the user's browser.

flush()The function does not affect the caching mode of the server or client browser.
Therefore, you must use both ob_flush() the and flush() functions to flush the output buffers.

ob_flush

Flushes out the contents of the output buffer

The contents of the output buffer, if you want to further process the contents of the buffer, must be ob_flush() called ob_get_contents() before ,
Because the ob_flush() buffer content is discarded after the call, the buffer is not destroyed.

ob_end_flush

Output buffer contents, and close the output buffer.

ob_get_flush

The output buffer content (returned as a string), and the output buffer is closed, unlike ob_end_flush() This function also returns the buffer contents as a string.

ob_clean

Empties the output buffer, which is used to discard the contents of the output buffer

This function does not ob_end_clean() destroy the output buffers as functions do.

The output buffer must have ob_start() been PHP_OUTPUT_HANDLER_CLEANABLE started with a flag. Otherwise it ob_clean() will not be effective.

ob_end_clean

Empties the output buffer and closes the output buffer; This function discards the contents of the topmost output buffer and closes the buffer

ob_get_clean

Gets the contents of the current buffer and deletes the current output cache

Returns the contents of the output buffer and ends the output buffer. Returns if the output buffer is not active FALSE .

ob_get_conents

Gets the contents of the buffer

ob_get_length

Gets the length of the buffer content

ob_get_level

Gets the nesting level of the buffering mechanism

ob_get_status

Get the status of all output buffers

Output function Generation static Page example Demo:
1<?PHP2    //Open Output Control cache3    Ob_start();4    Echo";5    //gets the contents of the buffer6    $out=ob_get_contents();7    //Turn off output caching8    Ob_end_clean();9    //Open the test.html file to turn on write accessTen    $fp=fopen("Test.html", "W"); One    if(!$fp) { A        Echo"Fail"; die; -}Else { -        //Write File the        fwrite($fp,$out); -        //Close File -        fclose($fp); -        Echo"Success"; +}

Output: Success simultaneously outputs a static page such as

PHP output control functions and output functions generate static pages

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.