PHP Output Buffering
(Page 1 of 5 )
This tutorial will procede first by enumerating the functions used in output buffering with a brief explanation of each. Then we will examine how these functions are utililized. We will conclude with three brief examples of scenerios where one might use output buffering.
By : Michael Bailey
Today I want to answer a question which has vexed mankind for centuries, "How do I get my suit dry-cleaned without that disgusting chemical smell? And can I get it done overnight?" Unfortunately, I don't have the slightest idea how to answer that question, so I'm forced instead to discuss output buffering in PHP. That's how life is some times.
Output buffering is a powerful tool in PHP which allows you to buffer a script's output. You can then edit this buffer before returning it to the client.
This tutorial will procede first by enumerating the functions used in output buffering with a brief explanation of each. Then we will examine how these functions are utililized. We will conclude with three brief examples of scenerios where one might use output buffering. Without further ado then, we will procede to...
Output Buffering Functions Our toolbox of functions dealing with output buffering is fairly small. The following are the most common functions. The full list can be obtained from the PHP website.
ob_start([callback function]) - Starts an output buffering session. ob_flush() - Send the contents of the buffer to the client and clear the buffer. ob_get_contents() - Returns the contents of the buffer. The buffer is not cleared. ob_end_clean() - Ends the current buffering session and purges the buffer. ob_end_flush() - Ends the current buffering session and displays the buffer. ob_get_length() - (Version >= 4.0.2) Return the size of the current buffer. ob_get_clean() - (Version >= 4.3) Composite of ob_get_contents() and ob_end_clean(). The buffer is returned and the session ends. |
Next: How It's Done >>
More Miscellaneous Articles
More By Codewalkers