Generate PHP static (HTML) page program code _php Tutorial

Source: Internet
Author: User
Generating a static page is usually a dynamic page generated HTML pages, which can reduce the server load is now the major sites commonly used optimization method, below I would like to share a PHP generated static (HTML) page class.
The code is as follows Copy Code

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

?>


http://www.bkjia.com/PHPjc/444648.html www.bkjia.com true http://www.bkjia.com/PHPjc/444648.html techarticle generating a static page is usually a dynamic page generated HTML pages, which can reduce the server load is now the major sites commonly used optimization method, below I would like to share a PHP generated static ...

  • Related Article

    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.