Hate those ugly error messages that PHP generates when it encounters an error in your scripts? Can't stand half-constructed Web pages? Well, maybe you should take a look at PHP's output control functions, which offer an interesting and powerful solution to the problem.
Let's take a closer look at the output control functions available in PHP. Everything begins with the ob_start() function, which actually initializes an output buffer for use within the script.
<?php// start buffering the outputob_start();?>
The ob_start() function doesn't really need much explanation. Call it, and an output buffer opens up, ready to intercept and suck in whatever output is generated by the script.
As you will see in subsequent examples, it's possible to use this output buffer in combination with a user-defined handler to reprocess and modify the output of the script as it enters the buffer.
Once a buffer has been defined, the script proceeds to execute as usual. When you've decided that it's time to dispay the contents of the buffer to the user, you can simultaneously end output buffering and send the contents of the current buffer to the browser via a call to ob_end_flush().
<?php// print the contents of the bufferob_end_flush();?>
Thus, the ob_start() and ob_end_flush() functions act as a wrapper around your script, controlling the display of script output as per your whims and fancies.