您的位置: 首页 - PHP代码 - PHP中生成纯静态html页面

PHP中生成纯静态html页面

编辑:admin     时间:2010-12-26    22:24:31  来自:北京蓝网网络技术有限公司

提取数据库中的的某表,生成html静态页面,tem.html是模板页面其中 {title} {content}为标签, 代码为

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{title}</title>
</head>
<body>
网站内容是:{content}
</body>
</html>

<?php
header('content-type:text/html;charset=utf-8');
$conn=mysql_connect('localhost','root','123456') or die('数据库服务器连接错误'.mysql_error());
mysql_select_db('student',$conn) or die('数据库错误'.mysql_error());
mysql_query('set names utf8');
$result=mysql_query("select * from info");
?>
<?php
while(!!$row=mysql_fetch_array($result)){
    $path=$row['id'].'.html';
    $title=$row['name'];
    $content=$row['name'];

$fp=fopen('tem.html','r');
$str=fread($fp,filesize('tem.html'));
$str=str_replace('{title}',$title,$str);
$str=str_replace('{content}',$content,$str);
fclose($fp);
$con=fopen($path,'w');
fwrite($con,$str);
fclose($con);
}

?>

分类:PHP代码 | 评论:0 | 引用:0 | 浏览:253  | 引用本文