批量生成静态页面,如有不合理指点

<!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="Content-Type" content="text/html; charset=gb2312" />
<title>生成静态页面</title>
</head>
<?php
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."<br />".$path;
}
echo "生成静态页面成功!".$url;
exit;
?>
<body>
</body>
</html>
 

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Grow your business fast with

Suku