Home Backend Development PHP Tutorial Use PHP to generate static HTML fast class library_PHP tutorial

Use PHP to generate static HTML fast class library_PHP tutorial

Jul 21, 2016 pm 03:56 PM
html include php start code copy turn on server generate use Class library cache high speed static

Copy code The code is as follows:

ob_start();#Enable server caching
include_once 'Index.php';
$ctx=ob_get_contents();# Get cache
ob_end_clean();#Clear cache
$fh=fopen("index.html","w+");
fwrite($fh, $ctx);# Write html and generate html
fclose($fh);

1. Flush: refresh the contents of the buffer and output.
Function format: flush()
Description: This function is frequently used and is very efficient.
2. ob_start: Open the output buffer
Function format: void ob_start(void)
Description: When the buffer is activated, all non-file header information from the PHP program will not be sent, but saved. in the internal buffer. In order to output the contents of the buffer, you can use ob_end_flush() or flush() to output the contents of the buffer.
3. ob_get_contents: Returns the contents of the internal buffer.
Use
function format: string ob_get_contents(void)
Description: This function will return the contents of the current buffer. If the output buffer is not activated, it will return FALSE.
4. ob_get_length: Returns the length of the internal buffer.
Usage: int ob_get_length(void)
Description: This function will return the length in the current buffer; the same as ob_get_contents, if the output buffer is not activated. then returns FALSE.
5. ob_end_flush: Send the contents of the internal buffer to the browser and close the output buffer.
Usage: void ob_end_flush(void)
Description: This function sends the contents of the output buffer (if any).
6. ob_end_clean: Delete the contents of the internal buffer and close the internal buffer
Usage method: void ob_end_clean(void)
Description: This function will not output the contents of the internal buffer but delete it !
7. ob_implicit_flush: Turn on or off absolute refresh
Usage: void ob_implicit_flush ([int flag])
Copy the code The code is as follows:

////////////////////////////////////// ///////////////////////////////////////////
//
// Zhang Shulin - Huijia Studio
//
// Module Name: woods-bhtml.php
// Abstract: Generate static HTML handler bottom
// 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, Hoojar studio All Rights Reserved

//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 the
/ /above copyright notice. By the software Huijia studio
//maintenance, if you have any queries please contact us.
//Thank you.
//
//This software is free software, You are allowed to use, copy, modify, and distribute this software and its documentation.
//A copy of the above copyright notice must appear wherever this software is used. This software is maintained by
//Huijia Studio. If you have any questions, please contact us. Thank you for using it.
//
//////////////////////////////////////////// ////////////////////////////////////////
//This file can only be loaded in the program Last
/*______________Generate HTML file_______________beign____________________________*/
if ($make_html)
{
$buffer = ob_get_flush();
if ($go_html)//Is it direct Switch to HTML file display or PHP read content output (0: PHP read content output 1: direct transfer)
{
/*__________ handle the path problems caused by generating 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);
/*__________ handles seed path problems caused by generating HTML files____________________end_______________*/
}

$fp = fopen(HTML_FILE, "w");
if ($fp)
{
fwrite($fp, $buffer);
fclose($fp);
}
}
/*______________Generate HTML file____________________beign____________________________*/
?>

///////////////// ////////////////////////////////////////////////////// ////////////
//
// Zhang Shulin-Huijia Studio
//
// Module Name: woods-thtml.php
/ / Abstract: Generate static HTML handler 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 copyright protection 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 the
//above copyright notice. By the software Huijia studio
//maintenance, if you have any queries please contact us.
// Thank you.
//
//This software is free software, and you are allowed to use, copy, modify, and distribute this software and its documentation.
//A copy of the above copyright notice must appear wherever this software is used. This software is maintained by
//Huijia Studio. If you have any questions, please contact us. Thank you for using it.
//
//////////////////////////////////////////// ////////////////////////////////////////
//This file can only be loaded in the program Beginning
ob_start();
/*___________ determines whether the HTML file has been generated. If so, 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())//Determine whether the last time the HTML file was generated was 1 time in the past. If not, the file content will be output directly
{
if ($ show_html)//Whether to display as HTML static page (0 does not display in HTML 1 displays in html)
{
if ($go_html)//Whether to directly go to the HTML file display or PHP to read the content output (0:php read content output 1: direct transfer)
{
header("Location: " . HTML_FILE);//direct transfer
}
else
{
echo( file_get_contents(HTML_FILE));//Read the display
}
exit(0);
}
}
}
/*___________ Determine whether the HTML file has been generated, If generated, 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 copyrights protected 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 the
//above copyright notice. By the software Huijia studio
//maintenance, if you have any queries please contact us.
//Thank you.
/ /
//This software is free software, and you are allowed to use, copy, modify, and distribute this software and its documentation.
//A copy of the above copyright notice must appear wherever this software is used. This software is maintained by
//Huijia Studio. If you have any questions, please contact us. Thank you for using it.
//
//////////////////////////////////////////// ///////////////////////////////////////
require("woods-thtml.php") ;//Generate HTML processing header
//if (count($_GET) < 1 && count($_POST) < 1){require("woods-thtml.php");}//Generate HTML processing Header

require("{$exec_file}");//Register language definition file
foreach ($lang as $key => $value)
{
$atpl[strtoupper ($key) ."_LANG"] = $value;
}
/*______________________________ List common sense items going up __________________end___________*/
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 operation_________________________end_______________________________*/
require(" woods-bhtml.php");//Generate HTML processing tail
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318133.htmlTechArticleCopy the code as follows: ob_start();#Enable server caching include_once 'Index.php'; $ctx=ob_get_contents ();# Get the cache ob_end_clean();# Clear the cache $fh=fopen("index.html","w+...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

React's Role in HTML: Enhancing User Experience React's Role in HTML: Enhancing User Experience Apr 09, 2025 am 12:11 AM

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

See all articles