Output Buffer Function
Author: Kh9 Joined: 2003-11-22 Views: 117 PHP programming, we often encounter some function directly generated output, such as passthru (), readfile (), var_dump (), etc. But sometimes we want. Import the output of these functions into the file or processed before processing, or processes the output of these functions as a string. At this time we have to use the Output Buffer function. The function of processing the output buffer mainly has such a few: ob_start () starts output buffer, at this time, PHP stops the 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 there is a special character of <,> and other HTML in the content of the variable, it will not see it in the output to the web. 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 (); This time var_dump () output has already existing $ OUT. You can output it now: Echo '
'. htmlspecialchars $ out). ' pre>'; or wait until the future or send this string to the template (Template).