Home > Backend Development > PHP Tutorial > Output control class_PHP tutorial

Output control class_PHP tutorial

WBOY
Release: 2016-07-21 16:07:47
Original
929 people have browsed it

/**
*
* Author: Xu Zuning (Nagging)
* Email: czjsz_ah@stats.gov.cn
* Developed: 2002.07
*
*
* Category: outbuffer
* Function: Encapsulate some output control functions and control the output object.
*<*>*Method:
*Run ($ PROC) Run the PHP program
*$ PROC PHP program name
*Display () Output operation
*Savetofile ($ FILENAME) Save the running results to a file, which can generally 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","rn",$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);
  }
}
?>


http://www.bkjia.com/PHPjc/315018.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/315018.htmlTechArticle?php /** * *作者: 徐祖宁 (唠叨) *邮箱: czjsz_ah@stats.gov.cn *开发: 2002.07 * * *类: outbuffer *功能: 封装部分输出控制函数,控制输出对象。 * *方法:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template