一个简单的实例:
新闻模版文件news_tmp.html:
{news_title} |
{news_image} |
{news_content} |
$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
";
$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:
Hello {hello}
PHP文件代码:
$title = 'webjx';
$hello = 'webjxcom!';
$file = file_get_contents('templets.htm');
$file = str_replace(array('{title}','{hello}'),array($title,$hello), $file);
echo $file;
?>
查看(48) 评论(0) 收藏 推荐
2007-11-20 11:21:18
查看(12) 评论(1) 收藏 推荐
2007-11-18 14:18:21
查看
PHP-smarty安装
模板页index.tpl:
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<{*assignvar="login"value=0*}>
<{sectionname=lploop=$ly}> 留言人: 标题:<{$ly[lp].tm}> |