Home arrow PHP arrow Page 4 - Output Buffering With PHP

Melting Down - 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
Of course, there aren't just two functions available to you - the output control API has a few other cards up its sleeve as well. Consider the following example:

<?php// run at script startfunction page_init(){ // start buffering the output ob_start();}// run at script endfunction page_exit(){ global $error; // if an error occurred // erase all output generated so far // and display an error message if ($error == 1) { ob_end_clean(); print_error_template(); } // no errors? // display output else { ob_end_flush(); }}// print error pagefunction print_error_template(){ echo "<html><head><basefont face=Arial></head><body>An erroroccurred. Total system meltdown now in progress.</body></html>"; }page_init();// script code goes hereecho "This script is humming like a well-oiled machine";// if an error occurs// set the global $error variable to 1// uncomment the next line to see what happens if no error occurs $error= 1;page_exit();?>
In this case, depending on whether or not a particular error condition is met, PHP will either display the contents of the buffer, or wipe it clean via the ob_end_clean() function.

 
 
>>> 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: