php output buffer control

伊谢尔伦
Release: 2016-11-22 09:51:27
Original
1075 people have browsed it

Introduction

When a PHP script has output, the output control function can use these to control the output. This is useful in a number of different situations, especially for sending http headers to the browser after the script has started outputting data. The output control function does not affect the file header information sent by header() or setcookie(), only the data between functions like echo and PHP code blocks.

Note:

Due to defects in earlier versions, when upgrading from PHP4.1.x (4.2.x, 4.3.x), you must ensure that implicit_flush in php.ini is OFF, otherwise any use of ob_start() The output will be hidden in the output.

Basic usage

<?php
    ob_start();
    echo "Hello\n";
    setcookie("cookiename", "cookiedata");
    ob_end_flush();
?>
Copy after login

In the above example, the output of the echo function will be saved in the output buffer until ob_end_flush() is called. At the same time, the call to setcookie() also successfully stores a cookie without causing an error. (Under normal circumstances, after the data is sent to the browser, the http header information can no longer be sent.)

Output control function

flush — Flush the output buffer

ob_clean — Clear (erase) the output buffer

ob_end_clean — Clear (erase) the buffer and close the output buffer

ob_end_flush — Flush (send out) the contents of the output buffer and close the buffer

ob_flush — Flush (send) the contents of the output buffer

ob_get_clean — Get the current The contents of the buffer and delete the current output buffer.

ob_get_contents — Returns the contents of the output buffer

ob_get_flush — Flushes (sends out) the buffer contents, returns the content as a string, and closes the output buffer.

ob_get_length — Returns the length of the output buffer content

ob_get_level — Returns the nesting level of the output buffer mechanism

ob_get_status — Gets the status of all output buffers

ob_gzhandler — Used in ob_start to compress the output buffer Content callback function.

ob_implicit_flush — Turn on/off absolute flushing

ob_list_handlers — List all output handlers in use.

ob_start — Turn on the output control buffer

output_add_rewrite_var — Add URL rewriter values ​​

output_reset_rewrite_vars — Reset URL rewriter values ​​


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template