- <?php
- 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){
- //替換模板字符串中<FIELD_$key> 的字符串
- $tmp = str_replace('<FIELD_'.$key.'>',$value,$tmp);
- }//開源代碼Vevb.com
- //生成文件,存盤。
- $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="標題:<FIELD_title>內容:<FIELD_content>";
- $obj->BindData($arr);
- //一切OK,萬事達吉
- $obj->Create();*/
- ?>
新聞熱點
疑難解答