Output Control class

Source: Internet
Author: User

<? 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 );
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.