代码如下 | 复制代码 |
class create_html { private $template; //模版 private $file_name; //文件名 private $array; //数据数组 function __construct($file_name, $template, $array) { //构造类 $this->template = $this->read_file($template, "r"); //读取模板文件 $this->file_name = $file_name; $this->array = $array; //数据数据 $this->html(); //生成html } function html() { //生成html while (ereg ("{([0-9]+)}", $this->template, $regs)) { //循环模版中所能的{1}….. $num = $regs[1]; //得到1、2、3序列 $this->template = ereg_replace("{".$num."}", $this->array[$num], $this->template); //把数据替换成html内容 $this->write_file($this->file_name, $this->template, "w+"); //生成HTML文件 } } function read_file($file_url, $method = "r") { //读取文件 $fp = @fopen($file_url, $method); //打开文件 $file_data = fread($fp, filesize($file_url)); //读取文件信息 return $file_data; } function write_file($file_url, $data, $method) { //写入文件 $fp = @fopen($file_url, $method); //打开文件 @flock($fp, LOCK_EX); //锁定文件 $file_data = fwrite($fp, $data); //写入文件 fclose($fp); //关闭文件 return $file_data; } } #例子———————- #读取邮件回复模版———————————————————————————- $title = "标题"; $navigation = "浏览器"; $happy_origin = "作者"; $name = "test2.htm"; $template = "default_tmp.php"; //模版中用{1}{2}来替换 $daytype = array(1 => $title, 2 => $navigation, 3 => $happy_origin); $htm = new Restore_email($template, $daytype); echo $htm->pint(); ?> |
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔