How to use the OutputBuffer buffer output function

Source: Internet
Author: User
An excellent use of the output buffer function of OutputBuffer. In PHP programming, we often encounter some functions that directly generate output, such as passthru (), readfile (), and var_dump. but sometimes we want to import the output of these functions into files, or in PHP programming, we often encounter some functions that directly generate output, such as passthru (), readfile (), var_dump () and so on. however, sometimes we want to import the output of these functions to a file, or process the output of these functions as strings. now we need to use the Output Buffer function. there are several main functions for processing the output buffer: ob_start () starts to output the buffer, and PHP stops the output. after that, the output is forwarded to an internal buffer. the ob_get_contents () function returns the content of the internal buffer. this is equivalent to converting all these outputs into strings. ob_get _ length () returns the length of the internal buffer. ob_end_flush ( ) Ends the output buffer and outputs the content in the buffer. after that, the output is normal. ob_end_clean () ends the output buffer and discards the content in the buffer. for example, the var_dump () function outputs the structure and content of a variable, which is useful during debugging. however, if the variable contains special characters such as <,> in HTML, the output will not be seen in the webpage. what should we do? The output buffer function can easily solve this problem. ob_start (); var_dump ($ var); $ out = ob_get_contents (); ob_end_clean (); the output of var_dump () already exists in $ out. now you can output: echo
. Htmlspecialchars ($ out ).
; Or wait until the future, or send this string to the Template before output.

Functions, such as passthru (), readfile (), and var_dump. but sometimes we want to import the output of these functions into a file, or...

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.