Home > Backend Development > PHP Tutorial > Radio enthusiasts PHP function to generate static pages, recommended by PHP enthusiasts site

Radio enthusiasts PHP function to generate static pages, recommended by PHP enthusiasts site

WBOY
Release: 2016-07-29 08:36:46
Original
1385 people have browsed it

Copy the 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 as static.php
Execute the following Page phpfans.php

Copy the code The code is as follows:


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



Untitled Document


echo "Welcome to this site, http://www.jb51.net";
?>


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

The above introduces the PHP function for generating static pages for radio enthusiasts. Recommended by the PHP Enthusiast Station, including content about radio enthusiasts. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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