In PHP programming, we often encounter some functions that directly generate output, such as passthru (), readfile (), and var_dump. 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, var_dump () The 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.