Home arrow PHP arrow Page 3 - Output Buffering With PHP

Start Me Up - PHP

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.

TABLE OF CONTENTS:
  1. Output Buffering With PHP
  2. The Matrix Awaits
  3. Start Me Up
  4. Melting Down
  5. Today's Forecast
  6. Making It Simpler
  7. The Real World
  8. Zip Zap Zoom
  9. Endgame
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 69
April 30, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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.

 
 
>>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap

Dev Shed Tutorial Topics: