The output isn't all that exciting, simply Hello World in single quotes. The function ob_start() initiates the output buffering. "Hello World" is then printed, but it does not get sent to the client. Instead it is buffered until we do something with it. That we do by storing the buffer in $buffer by calling ob_get_contents(). ob_end_clean() ends the output buffering, which means that the last print command displays to the client.
Nested Output Buffering
You might be asking what happens if you call ob_start() twice without closing the buffer. PHP's real smart, so it handles it very nicely by nesting the buffers. The following script shows how this is done.
<?php // Open buffer #1 ob_start(); print "Line 1\n";
// Open buffer #2 ob_start(); print "Line 2\n";
// Grab the contents of buffer #2 $buf2 = ob_get_contents();
// Close buffer #2 ob_end_clean(); print "Line 3\n";
// Grab the contents of buffer #1 $buf1 = ob_get_contents();
// Close buffer #1 ob_end_clean();
// Output the buffer contents print $buf1; print $buf2; ?>
Without knowledge of output buffering, one would expect the lines to be printed in numerical order. This is not the case though. After printing line 1, a second buffer is opened which prints line 2 and captures the buffer. Line 3 is then printed in the first buffer. The first buffer captures lines 1 and 3 while the second captures line 2.
What all this means is that you can build functions and scripts with output buffering without worrying about fouling up an algorithm nested below or above in the logic. As long as you always remember to close every buffer you open, you won't have any problems.