Use PHP to generate a static HTML high-speed class library _ php instance

Source: Internet
Author: User
Use PHP to generate static HTML code. For more information, see. 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
?>

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.