Use PHP to generate static HTML fast-speed class library _ PHP Tutorial

Source: Internet
Author: User
Use PHP to generate a static HTML library with high speed. Copy the code as follows: drawing, w + The code is as follows:


Ob_start (); # enable server cache
Include_once 'index. php ';
$ Ctx = ob_get_contents (); # get cache
Ob_end_clean (); # clear the cache
$ Fh = fopen ("index.html", "w + ");
Fwrite ($ fh, $ ctx); # write html to generate html
Fclose ($ fh );


1. Flush: refresh the buffer content and output it.
Function format: flush ()
Note: This function is frequently used and highly efficient.
2. ob_start: Open the output buffer.
Function format: void ob_start (void)
Note: When the buffer zone is activated, all non-file header information from the PHP program is not sent, but stored in the internal buffer zone. To output the buffer content, you can use ob_end_flush () or flush () to output the buffer content.
3. ob_get_contents: returns the content of the internal buffer.
Use
Function format: string ob_get_contents (void)
Note: This function returns the content in the current buffer. if the output buffer is not activated, FALSE is returned.
4. ob_get_length: return the length of the internal buffer.
Usage: int ob_get_length (void)
Note: This function returns the length of the current buffer. it is the same as ob_get_contents if the output buffer is not activated. Returns FALSE.
5. ob_end_flush: sends the content of the internal buffer to the browser and closes the output buffer.
Usage: void ob_end_flush (void)
Note: This function sends the content of the output buffer (if any ).
6. ob_end_clean: delete the content of the internal buffer and disable the internal buffer.
Usage: void ob_end_clean (void)
Note: This function will not output the content of the internal buffer but delete it!
7. ob_implicit_flush: enable or disable absolute refresh
Usage: void ob_implicit_flush ([int flag])

The code is as follows:


//////////////////////////////////////// ///////////////////////////////////////
//
// Zhang Shulin-Huijia Studio
//
// Module Name: woods-bhtml.php
// Abstract: generate the end of the static HTML processing program
// Version 2.0
// Date 1006-11-25
// Author: woods · zhang
// Website: http://www.hoojar.com/
// Email: hoojar@53.com
// MSN: hoojar@hotmail.com
// Copyright 1001-1006, Hoojar studio All Rights Reserved
//
// Copyright 1001-1006, all rights reserved by Huijia Studio

// The software for free software, allowing use, copy,
// Modify and distribute the software and files. Any
// Use of this software must place a copy of all
// Above copyright notice. By the software Huijia studio
// Maintenance, if you have any queries please contact us.
// Thank you.
//
// This software is a free software that allows the use, copying, modification, and distribution of the software and its documentation.
// All copies of the above copyright notice shall appear wherever the software is used. This software is developed
// Maintain Huijia studio. if you have any questions, please contact us. Thank you for using it.
//
//////////////////////////////////////// ///////////////////////////////////////
// This file can only be loaded at the end of the program
/* ________________ Generate the HTML file ______________________ beign ________________________________*/
If ($ make_html)
{
$ Buffer = ob_get_flush ();
If ($ go_html) // whether to directly convert to HTML file display or PHP read content output (0: php read content output 1: directly convert)
{
/* __________ Handle the path problem arising from the generation of HTML files ____________________ begin _______________*/
$ Search = array (
"/(Src = | action = | href = | ajaxRead \ () \"/ie ",
"/\./E ",
"/\. \/\./E ",
"/\. \. \/Http: \/ies ",
"/\.\.\/#/",
"/\ '\. \'/E ",
"/\. \. \/Javascript:/ies ");

$ Replace = array (
"'\ 1 \"../'",
"'..'",
"'.'",
"'Http ://'",
"#",
"'\'..\''",
"'Javascript :'");
$ Buffer = preg_replace ($ search, $ replace, $ buffer );
/* __________ Handle the path problem arising from the generation of HTML files ____________________ end _______________*/
}

$ Fp = fopen (HTML_FILE, "w ");
If ($ fp)
{
Fwrite ($ fp, $ buffer );
Fclose ($ fp );
}
}
/* ________________ Generate the HTML file ______________________ beign ________________________________*/
?>

//////////////////////////////////////// ///////////////////////////////////////
//
// Zhang Shulin-Huijia Studio
//
// Module Name: woods-thtml.php
// Abstract: generate a static HTML processing program header
// Version 2.0
// Date 1006-11-25
// Author: woods · zhang
// Website: http://www.hoojar.com/
// Email: hoojar@53.com
// MSN: hoojar@hotmail.com
// Copyright 1001-1006, Hoojar studio All Rights Reserved
//
// Copyright 1001-1006, all rights reserved by Huijia Studio

// The software for free software, allowing use, copy,
// Modify and distribute the software and files. Any
// Use of this software must place a copy of all
// Above copyright notice. By the software Huijia studio
// Maintenance, if you have any queries please contact us.
// Thank you.
//
// This software is a free software that allows the use, copying, modification, and distribution of the software and its documentation.
// All copies of the above copyright notice shall appear wherever the software is used. This software is developed
// Maintain Huijia studio. if you have any questions, please contact us. Thank you for using it.
//
//////////////////////////////////////// ///////////////////////////////////////
// This file can only be loaded at the beginning of the program
Ob_start ();
/* ___________ Determine whether an HTML file has been generated. If an HTML file has been generated, the page will jump to the HTML page ___________ begin __________*/
$ Qstring = isset ($ _ SERVER ["QUERY_STRING"])? $ _ SERVER ["QUERY_STRING"]: "";
If ($ qstring) // The program adds GET request processing
{
$ Qstring = str_replace ("=", "", $ qstring );
Define ("HTML_FILE", "./h/{$efilename}-{$qstring}.html ");
}
Else
{
Define ("HTML_FILE", "./h/{$efilename}.html ");
}
If (file_exists (HTML_FILE ))
{
$ Lcft = filemtime (HTML_FILE); // last create file time
If ($ lcft + 3600)> time () // determines whether the last HTML file was generated for the past 1 time. if not, the file content is output directly.
{
If ($ show_html) // whether to display static HTML pages (0 is not displayed in HTML, 1 is displayed in html)
{
If ($ go_html) // whether to directly convert to HTML file display or PHP read content output (0: php read content output 1: directly convert)
{
Header ("Location:". HTML_FILE); // directly convert
}
Else
{
Echo (file_get_contents (HTML_FILE); // Read display
}
Exit (0 );
}
}
}
/* ___________ Determine whether an HTML file has been generated. If an HTML file is generated, the page will jump to the HTML page ___________ end __________*/
?>

//////////////////////////////////////// ///////////////////////////////////////
//
// Zhang Shulin-Huijia Studio
//
// Module Name: index. php
// Abstract: home page information
// Version 1.0
// Date 2006-11-7
// Author: woods · zhang
// Website: http://www.hoojar.com/
// Cemail: hoojar@163.com
// MSN: hoojar@hotmail.com
// Copyright 2001-2006, Hoojar studio All Rights Reserved
//
// Copyright 2001-2006, all rights reserved by Huijia Studio

// The software for free software, allowing use, copy,
// Modify and distribute the software and files. Any
// Use of this software must place a copy of all
// Above copyright notice. By the software Huijia studio
// Maintenance, if you have any queries please contact us.
// Thank you.
//
// This software is a free software that allows the use, copying, modification, and distribution of the software and its documentation.
// All copies of the above copyright notice shall appear wherever the software is used. This software is developed
// Maintain Huijia studio. if you have any questions, please contact us. Thank you for using it.
//
//////////////////////////////////////// ///////////////////////////////////////
Require ("woods-thtml.php"); // Generate an HTML processing header
// If (count ($ _ GET) <1 & count ($ _ POST) <1) {require ("woods-thtml.php") ;}// generate an HTML processing header

Require ("{$ exec_file}"); // register the language definition file
Foreach ($ lang as $ key => $ value)
{
$ Atpl [strtoupper ($ key). "_ LANG"] = $ value;
}
/* ________________________________________________ List items going up with common sense _____________________*/
Include ("woods-templates.php ");
$ Tpl = new WoodsTpl ("./templates /");
$ Tpl-> require_tpl ("header.html ");
$ Tpl-> set_file ();
$ Tpl-> block ("EBCORP", $ scorp );
$ Tpl-> block ("NEWS", $ news );

$ Tpl-> block ("PRODUCT", $ product );
$ Tpl-> block ("EBPNAME_MSG", $ spname );

$ Tpl-> block ("LORE", $ lore );
$ Tpl-> require_tpl ("footer.html ");
$ Tpl-> parse ($ atpl, true );
$ Tpl = NULL;
/* ________________ Template operations _________________________ end ___________________________________*/
Require ("woods-bhtml.php"); // Generate the end of HTML processing
?>

The http://www.bkjia.com/PHPjc/318133.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/318133.htmlTechArticle code is as follows: ob_start (); # enable the server cache include_once 'Index. php '; $ ctx = ob_get_contents (); # get the cache ob_end_clean (); # clear the cache $ fh = fopen ("index.html", "w +...

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.