<?php Class Create_html { Private $template; Mould Plate Private $file _name; Filename Private $array; Array of data function __construct ($file _name, $template, $array) { Construct class $this->template = $this->read_file ($template, "R"); Reading template files $this->file_name = $file _name; $this->array = $array; Data data $this->html (); Generate HTML } function html () { Generate HTML while (Ereg ("{[0-9]+)}", $this->template, $regs)) { {1} In the loop template ... $num = $regs [1]; Get 1, 2, 3 sequences $this->template = ereg_replace ("{". $num. "}", $this->array[$num], $this->template); Replace the data with HTML content $this->write_file ($this->file_name, $this->template, "w+"); Generate HTML file } } function Read_file ($file _url, $method = "R") { Reading files $fp = @fopen ($file _url, $method); Open File $file _data = fread ($fp, FileSize ($file _url)); Reading file information return $file _data; } function Write_file ($file _url, $data, $method) { Write to File $fp = @fopen ($file _url, $method); Open File @flock ($fp, LOCK_EX); Lock file $file _data = fwrite ($fp, $data); Write to File Fclose ($FP); Close File return $file _data; } } #例子 ———————- #读取邮件回复模版 ———————————————————————————- $title = "title"; $navigation = "Browser"; $happy _origin = "Author"; $name = "test2.htm"; $template = "default_tmp.php"; Replace with {1}{2} in stencil $daytype = Array (1 => $title, 2 => $navigation, 3 => $happy _origin); $htm = new Restore_email ($template, $daytype); echo $htm->pint (); ?> |