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 ); } //开源代码phpfensi测试数据 //生成文件,存盘。 $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();*/ ?>查看更多关于php shtml生成类带使用方法 - php类库的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did29502