Class Create_html { Private $template; Templates Private $file _name; Filename Private $array; Data array 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)) { The {1} that can be in the loop template ..... $num = $regs [1]; Get 1, 2, 3 sequence $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+"); Generating HTML files } } function Read_file ($file _url, $method = "R") { Read file $fp = @fopen ($file _url, $method); Open File $file _data = fread ($fp, FileSize ($file _url)); Read file information return $file _data; } function Write_file ($file _url, $data, $method) { Write file $fp = @fopen ($file _url, $method); Open File @flock ($fp, LOCK_EX); Lock file $file _data = fwrite ($fp, $data); Write file Fclose ($FP); Close File return $file _data; } } #例子 ———————- #读取邮件回复模版 ———————————————————————————- $title = "title"; $navigation = "Browser"; $happy _origin = "Author"; $name = "test2.htm"; $template = "default_tmp.php"; {1}{2} to replace the template $daytype = Array (1 = $title, 2 = $navigation, 3 = $happy _origin); $htm = new Restore_email ($template, $daytype); echo $htm->pint (); ?> |