Home > Backend Development > PHP Tutorial > PHP function to generate static pages, recommended by PHP enthusiasts site_PHP tutorial

PHP function to generate static pages, recommended by PHP enthusiasts site_PHP tutorial

WBOY
Release: 2016-07-21 15:56:16
Original
916 people have browsed it

Copy code The code is as follows:

function CreateShtml()
{
ob_start(" callback_CteateShtml");
}
function callback_CteateShtml($buffer)
{
$page = intval(@$_REQUEST["page"]);
//$fileName = $_SERVER[ 'DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/article/" . basename($_SERVER['PHP_SELF'],".php") . ($page==0 ? "" : "_ " . strval($page)) . ".html";
$fileName = basename($_SERVER['PHP_SELF'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".html";//You can modify your static page path here
$fp = fopen($fileName,"wb");
fwrite($fp,$buffer) ;
fclose($fp);
return $buffer;
}
?>


For example
Save the above code Execute the following page phpfans.php for static.php

Copy the code The code is as follows:

include("static.php");
CreateShtml();
?>



Untitled Document


echo "Welcome to Script House, http://www.jb51.net";
?>



A static page of phpfans.html will be generated
If there are parameters, use page to pass such as phpfans. php?page=1
will generate the static page of phpfans_1.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318079.htmlTechArticleCopy the code as follows: ?php functionCreateShtml() { ob_start("callback_CteateShtml"); } functioncallback_CteateShtml($buffer) { $page=intval(@$_REQUEST["page"]); //$fileName=$_...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template