批量生成静态页面[不合理请高手指点]
时间:2009-05-01
来源:互联网
本帖最后由 齐迹 于 2009-5-1 19:11 编辑
[php]
<!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>
[/php]
[php]
<!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>
[/php]
作者: 齐迹 发布时间: 2009-05-01
//$str 放到循环外围去. 重复读取是不理智的.
作者: 冯.于安 发布时间: 2009-05-01
有经验是不一样
为什么就想不到呢?
怎么实现 定时更新呢?
为什么就想不到呢?
怎么实现 定时更新呢?
作者: 齐迹 发布时间: 2009-05-01
html还定时?? 不要想得太多... 鸡肋功能, 不要考虑..
作者: 冯.于安 发布时间: 2009-05-01
可以吧查询 和 读写静态文件的操作抽出来,更好看
作者: phpbb 发布时间: 2009-05-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28