Section 11.4. Stacking Buffers


11.4. Stacking Buffers

Multiple output buffers can be open simultaneously, in which case, PHP writes to the most recently opened buffer. For example:

     ob_start( );     print "Hello first!\n";     ob_start( );     print "Hello second!\n";     ob_clean( ); 

That script will print out "Hello first!". The first buffer is started and filled with "Hello first", then a second buffer is started on top of the previous buffer, leaving the original still intact (though just out of reach for the time being). The new buffer is filled with "Hello second", but ob_clean( ) is called, clearing the most recent buffer and leaving the first untouched. The original buffer is then automatically sent by PHP when the script terminates.

Stacking output buffers becomes more important when you remember that it's generally smart to make your whole page buffered in a master buffer. Without stackable buffers, you would be unable to use any other buffers inside the main page.



PHP in a Nutshell
Ubuntu Unleashed
ISBN: 596100671
EAN: 2147483647
Year: 2003
Pages: 249

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net