亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home php教程 PHP開發(fā) Summary of methods for generating HTML pure static web pages from the entire website using PHP

Summary of methods for generating HTML pure static web pages from the entire website using PHP

May 14, 2018 pm 02:41 PM

<?php 
//在你的開始處加入 ob_start(); 
ob_start(); 

//以下是你的代碼 
//在結(jié)尾加入 ob_end_clean(),并把本頁輸出到一個變量中 
$temp = ob_get_contents(); 
ob_end_clean(); 

//寫入文件 
$fp = fopen(‘文件名&#39;,&#39;w&#39;); 
fwrite($fp,$temp) or die(‘寫文件錯誤&#39;); 
?>

This is just the most basic method, not very practical, because the website needs to be updated and HTML needs to be regenerated regularly
The following is the method I use:

if(file_exists(“xxx.html”)) 
{ 
$time = time(); 

//文件修改時間和現(xiàn)在時間相差半小時一下的話,直接導(dǎo)向html文件,否則重新生成html 
if($time - filemtime(“xxx.html”) < 30*60) 
{ 
header(“Location:xxx.html”); 
} 
} 
//在你的開始處加入 ob_start(); 
ob_start(); 

//頁面的詳細(xì)內(nèi)容 
//在結(jié)尾加入 ob_end_clean(),并把本頁輸出到一個變量中 
$temp = ob_get_contents(); 
ob_end_clean(); 

//寫入文件 
$fp = fopen(‘xxx.html&#39;,&#39;w&#39;); 
fwrite($fp,$temp) or die(‘寫文件錯誤&#39;); 

//重新導(dǎo)向 
header(“Location:xxx.html”);

The following is an introduction to some functions used:
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 will be 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: Return the contents of the internal buffer.
Usage: 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; like 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: 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 method: void ob_implicit_flush ([int flag])
Note: Anyone who has used Perl knows the meaning of $|=x. This string can open/close the buffer, and The ob_implicit_flush function is the same as that one. The default is to turn off the buffer. After turning on absolute output, each script output is sent directly to the browser, and there is no need to call flush().

More PHP will generate HTML pure static web pages for the entire website Please pay attention to the PHP Chinese website for related articles summarizing the methods!

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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)