php生成静态页面的简单实例
一个简单的实例:
新闻模版文件news_tmp.html:
<html>
<head>
<title>{title}</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<TABLE border=0 width=767 cellspacing="0" cellpadding="5">
<TR>
<TD>
<div align="center">{news_title}</div>
</TD>
</TR>
<TR>
<TD>
<div align="center">{news_image}</div>
</TD>
</TR>
<TR>
<TD>{news_content}</TD>
</TR>
</TABLE>
</body>
</html>
______________________________________________________________________________________________
答7:
新闻生成文件aaa.php:
<?
//假设下面信息都来自表单
$title="娱乐新闻---郑秀文准备宣布退出娱乐圈";
$news_title="郑秀文准备宣布退出娱乐圈";
$image_path=array("image/xxx.jpg","image/xxx2.jpg","image/xxx3.jpg");
$news_content="事业如日方中的郑秀文(Sammi),除是乐坛天后外,亦以五百五十万片酬登上全港片酬最高女星之位......";
$fp=@fopen("news_tmp.html","r") or die("没有模版文件或者没有相关权限!");
$str=fread($fp,filesize("news_tmp.html"));
fclose($fp);
______________________________________________________________________________________________
答8:
$news_filename=time().".html"; //生成的新闻文件名
$str=str_replace("{title}",$title,$str);
$str=str_replace("{news_title}",$news_title,$str);
$str=str_replace("{news_content}",$news_content,$str);
if(count($image_path)){
for($n=0;$n<count($image_path);$n++)
$news_image.="<img src=".$image_path[$n]."><BR>";
$str=str_replace("{news_image}",$news_image,$str);
}else
$str=str_replace("{news_image}","",$str);
$fw=fopen($news_filename,"w");
fwrite($fw,$str);
?>
文章网址:http://www.phprm.com/code/a0cc153477897a29eb39dff5ea56d0d4.html
随意转载^^但请附上教程地址。
- 上一篇: php批量上传五[带预览]
- 下一篇: 用ADODB实现事务