<? Php
/**
*
* Author: Xu zouning)
* Email: czjsz_ah@stats.gov.cn
* Development: 2002.07
*
*
* Class: outbuffer
* Function: encapsulate some output control functions to control output objects.
*
* Method:
* Run ($ proc) to run the php Program
* $ Proc php program name
* Display () Output running results
* Savetofile ($ filename) saves the running result to the file, which can be used to generate static pages.
* $ Filename file name
* Loadfromfile ($ filename): load the saved file
* $ Filename file name
*
* Example:
* 1.
* Require_once "outbuffer. php ";
* $ Out = new outbuffer ();
* $ Out-> run ("test. php ");
* $ Out-> display ();
*
* 2.
* Require_once "outbuffer. php ";
* Require_once "outbuffer. php ";
* $ Out = new outbuffer ("test. php ");
* $ Out-> savetofile ("temp.htm ");
*
* 3.
* Require_once "outbuffer. php ";
* $ Out = new outbuffer ();
* $ Out-> loadfromfile ("temp.htm ");
* $ Out-> display ();
*
*/
Class outbuffer {
Var $ length;
Var $ buffer;
Function outbuffer ($ proc = ""){
$ This-> run ($ proc );
}
Function run ($ proc = ""){
Ob_start ();
Include ($ proc );
$ This-> length = ob_get_length ();
$ This-> buffer = ob_get_contents ();
$ This-> buffer = eregi_replace ("\ r? \ N "," \ r \ n ", $ this-> buffer );
Ob_end_clean ();
}
Function display (){
Echo $ this-> buffer;
}
Function savetofile ($ filename = ""){
If ($ filename = "") return;
$ Fp = fopen ($ filename, "w ");
Fwrite ($ fp, $ this-> buffer );
Fclose ($ fp );
}
Function loadfromfile ($ filename = ""){
If ($ filename = "") return;
$ Fp = fopen ($ filename, "w ");
$ This-> buffer = fread ($ fp, filesize ($ filename ));
Fclose ($ fp );
}
}
?>