php代码:用Smarty批量生成html

文章摘要:经过一番摸索,终于找到方法,写出来大家指点一下: 首先在smartt.class.php中为Smarty类添加这么一个方法: PHP代码: //参数一:html文件保存路径,参数2:写入的内容 function MakeHtmlFile($file_name, $c) { if(!$fp = fopen($file_name, "wa")) { echo "文件打开失败!"; return false;
һϢϵͳܱǸύлʵкϵͳĹؼʻIPܵ˷ƣβЧϵͳѼ¼IPύݡע⣬ҪύκΥҹ涨ݣصϢΪgooglesyndication
/DTD XHTML 1.0 Transitional//EN" "[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">

<html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/url]">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title><{$news.titles}></title>

<link href="<{$docroot}>/CSS/main.css" rel="stylesheet" type="text/css" />

</head>

<body>

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="border:solid #CCCCCC 1px">

<tr>

<td height="25" colspan="6" align="center" bgcolor="#eeeeee"><strong><{$news.titles}></strong></td>

</tr>

<tr>

<td width="74" height="25" align="right">作者:</td>

<td widt

h="220"><{$news.author}></td>

<td width="40" align="right">时间:</td>

<td width="134" align="left"><{$news.sj}></td>

<td width="110" align="right">关键词:</td>

<td width="220" align="left"><{$news.keyword}></td>

</tr>

<tr>

<td height="25" align="right" >核心提示:</td>

<td height="25" colspan="5" class="artical" style="border:double #FF0000 3px;"><{$news.sumary}></td>

</tr>

<tr>

<td height="25" colspan="6" align="left" class="artical" style="padding:10px;"><{$news.contents}></td>

</tr>

</table>

</body>

</html>

总结:主要使用smarty的fetch方法,和文件的读写操作