批量生成静态页面,如有不合理指点_PHP教程
时间:2021-07-01 10:21:17
帮助过:14人阅读
生成静态页面
require_once class.inc/mysql.class.php;
$db= new DB_MySQL();
$db->query("select uid from user");
$uidrow=$db->get_rows_array();
$url="";
$fp=fopen("moban.html","r"); //只读打开模板
$str=fread($fp,filesize("moban.html"));//读取模板中内容
//于安大哥建议放循环外面
foreach($uidrow as $u){
$uid=$u[uid];
$sql="select * from user where uid=$uid";
$db->query($sql);
$rows=$db->get_rows_array();
$str=str_replace("{username}",$rows[0][username],$str);//替换内容
...........
fclose($fp);
$path="user/user-".$uid.".html";
$handle=fopen($path,"w"); //写入方式打开
fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件
fclose($handle);
$url=$url."
".$path;
}
echo "生成静态页面成功!".$url;
exit;
?>
http://www.bkjia.com/PHPjc/486480.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486480.htmlTechArticle!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml head meta http-equiv=Con...