Generate PHP static (HTML) page program code

Source: Internet
Author: User
The code is as follows Copy Code

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

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.