In PHP programming, we often encounter some functions that directly generate output, such as PASSTHRU (), readfile (), var_dump (), etc. But sometimes we want to import the output of these functions into the file, or before processing Output, or processes the output of these functions as a string.
At this time we have to use the Output Buffer function.
There are such a few functions to process the output buffer:
Ob_start () starts output buffer, at this time, PHP stops output, and the output after this is turned to an internal buffer.
Ob_get_contents () This function returns internal buffer content. This is equal to the string of these outputs into strings.
OB_GET_LENGTH () returns the length of the internal buffer.
OB_END_FLUSH () ends the output buffer and outputs the contents of the buffer. The output after this is normal output.
Ob_end_clean () ends the output buffer and throws away the contents of the buffer.
For example, the var_dump () function outputs the structure and content of a variable, which is useful when debugging.
However, if the content of the variable is <,> and other HTML special characters, it will not see it in the webpage. What should I do?
This problem can be easily solved with an output buffer function.
Ob_start ();
VAR_DUMP ($ VAR);
$ out = OB_GET_CONTENTS ();
Ob_end_clean ();
At this time, the output of var_dump () has already exists. You can output it now:
Echo '
'. HTMLSpecialchars ($ out). ' pre>';Or wait until the future, or send this string to the template (Template).