In PHP programming, we often encounter some functions that directly generate output, such as passthru (), readfile (), and var_dump. but sometimes we want to export the output of these functions to a file, or process and output them first, or use the output of these functions as a PHP programming, we often encounter some functions that directly generate output, such as passthru (), readfile (), and var_dump. however, sometimes we want to export the output of these functions to a file, or process the output of these functions as strings.
In this case, we need to use the Output Buffer function. There are several important functions for processing the Output Buffer:
Ob_start () begins to buffer the output, and PHP ends the output, after which the output is forwarded to an internal buffer. the ob_get_contents () function returns the content of the internal buffer. this means that all these outputs are converted 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 be invisible to the webpage. what should I do?
The output buffer function can easily solve this title. ob_start ();
Var_dump ($ var );
$ Out = ob_get_contents ();
Ob_end_clean ();
At this time, 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 outputting it.