PHP生成静态HTML页面实例代码
由于静态html页面更容易被搜索引擎收录,也能够减轻服务器的负载。很多时候我们都希望将动态语言的执行结果生成静态页面。
以下是一个PHP生成静态HTML页面的实例:
function wwwcopy($link, $file) {
$fp = @ fopen($link, "r");
while (!feof($fp)) {
$content .= fread($fp, 1024);
}
fclose($fp);
$fp2 = @ fopen($file, "w");
fwrite($fp2, $content);
fclose($fp2);
}
//Example on using this function
wwwcopy("http://phpcode8.com/?p=1", "p1.html");
//Another example
wwwcopy("http://phpcode8.com/?p=2", "p2.html");
本例的执行结果会生成2个静态文件。
浙公网安备 33010602011771号