Home >Backend Development >PHP Tutorial >How to generate functions for static pages in PHP_PHP Tutorial
How to generate a static page function:
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 here Page path
fp = fopen(fileName,"wb");
fwrite(fp,buffer);
fclose(fp);
return buffer;
}
?>Give me an example
Save the above code as static.php
Execute the following page phpfans.php
CODE:[Copy to clipboard] include("static.php");
CreateShtml();
?>
Untitled Document
echo "Welcome to php fans site, http://www.phpfans.net";
?>