php教程 shtml生成類帶使用方法
<?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);
}
//生成文件,存盤。
$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();*/
?>