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
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: