php生成静态代码,把php生成静态(html)页面程序代码_PHP教程

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();

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值