php静态登录demo,php生成静态页面的简单实例

\n

一个简单的实例:

新闻模版文件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.=”%E2%80%9D.image_path%5Bn%5D.%E2%80%9D
”;

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;

?>\n

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值