Home > php教程 > php手册 > php shtml生成类带使用方法

php shtml生成类带使用方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:23:16
Original
856 people have browsed it

php教程 shtml生成类带使用方法
 class Shtml{
  var $DataSource;        //array
  var $Templet;           //string
  var $FileName;
  
  //绑定数据源
  function BindData($arr){
   $this->DataSource = $arr;
  }
  
  function Create(){
  //只谈思路,自己写:
   $tmp = $this->Templet;
   foreach($this->DataSource as $key=>$value){
  //替换模板字符串中 的字符串
    $tmp = str_replace('',$value,$tmp);
   }
  //生成文件,存盘。
   $fp = fopen($this->FileName,'w');
   if (fwrite ($fp,$tmp)){
    fclose ($fp);
   }else {
    fclose ($fp);
   }
  }
 }
 
 //用法:
 /*$arr = array();
 $arr["title"] = "这里是标题";
 $arr["content"] = "这里是内容";
 $obj = new Shtml;
 $obj->FileName="xxx.htm";
 $obj->Templet="标题:内容:";
 $obj->BindData($arr);
 //一切OK,万事达吉
 $obj->Create();*/
?>


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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template