模板文件new.tpl
<{$news.titles}> | |||||
作者: | <{$news.author}> | 时间: | <{$news.sj}> | 关键词: | <{$news.keyword}> |
核心提示: | <{$news.sumary}> | ||||
<{$news.contents}> |
生成html文件函数写在smarty里面.
function MakeHtmlFile($file_name, $c)
{
if(!$fp = fopen($file_name, "wa"))
{
echo "文件打开失败!";
return false;
}
if(!fwrite($fp, $c))
{
echo "文件写入失败!";
fclose($fp);
return false;
}
fclose($fp);
}
n.php读取内容发送给smarty
include_once("config.php");
include_once("init.php");
$s->assign("title","所有的新闻分类");
$ID=$_GET["ID"]+0;
$sql="select * from artical where newsID=$ID";
$rs=$db->fetch($sql);
$s->assign("news",$rs["rec"][0]);//注意:$rs["rec"][0]是个数组
$s->display("news.html");
?>
生成文件使用makeHtmlFile
include_once("config.php");
include_once("init.php");
$sql="select * from artical";
$rs=$db->fetch($sql);
foreach ($rs["rec"] as $k=>$v)
{
$s->assign("news",$v);
$s->MakeHtmlFile("./news/news_".$v[0].".html",$s->fetch("news.html",null, null, false));
}
?>