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('
}
//生成文件,存盘。
$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();*/
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号