All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
php生成静态页面的简单实例_[PHP教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/2/17 7:38:29 Browse times: 436 Comment times: 0

php生成静态页面的简单实例_[PHP教程]


Head photo

Go homepage
Upload pictures
Write articles

php生成静态页面的简单实例_[PHP教程] 一个简单的实例:
新闻模版文件news_tmp.html:


{title}






{news_title}




{news_image}




{news_content}




______________________________________________________________________
答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 news_image.="
";
str=str_replace("{news_image}",news_image,str);
}else
str=str_replace("{news_image}","",str);
fw=fopen(news_filename,"w");
fwrite(fw,str);
?>



简单演示PHP如何使用模板生成静态页面。

模板文件templets.htm:



{title}


Hello {hello}





PHP文件代码:


title = 'dwww';
hello = 'dwwwcn!';
file = file_get_contents(’templets.htm’);
file = str_replace(array(’{title}’,’{hello}’),array(title,hello), file);
echo file;

?>





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.