使用PHPLIB模板 如何生成HTML最快 最合适/ echo $tpl->finish($tpl->get("out")); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的做法:一、修改template.inc加入以下的几个函数:/****************************************************************************** 函数:savetofile ($dir,$varname) 功能:将分析结果保存到文件中去 参数:$dir,$varname 文件路径,分析结果 */ function savetofile ($dir,$varname){ $data=$this->finish($this->get_var($varname)); $fp = fopen($dir,"w+"); fwrite($fp,$data); } /****************************************************************************** 函数:renew () 功能:清除已赋值数组,以免批生成文件的时候变量之间相互影响 参数:无 */ function renew(){ $this->varkeys = array(); $this->varvals = array(); //$this->file = array(); }二、生成静态文件过程(仅供参考)function staticInfo($aid){ global $db,$tbl,$template,$fpath,$file; $sql="SELECT title,content,hits,title_name,come_from,writer,datetime FROM $tbl where news_id=$aid"; $db->query($sql); $db->next_record(); //取出数据 $template->set_var(array("content" => $db->f("content"),"title" => $db->f("title"),"datetime" => $db->f("datetime"),"writer" => $db->f("writer"),"come_from" => $db->f("come_from"))); $template->parse("mains",$file); //把分析结果mains存入静态文件 $filename = ARTICLE_PATH.$fpath."/".srandnum().time().".htm"; $template->savetofile("../".$filename,"mains"); echo $filename."<br>"; //置空 $template->renew(); //把旧文件删除,新文件路径保存到数据库 $sql = "select filepath from $tbl where news_id=$aid and checked=1"; if($db->query($sql)){ $db->next_record(); @unlink("../".$db->f("filepath")); } //标识为已审核新闻 $sql = "update $tbl set filepath='$filename',checked=1 where news_id=$aid"; $db->query($sql);}$newslist = $_POST['fldTblList'];$id = explode(",",$newslist);for($i=0;$i<count($id);$i++){ staticInfo($id[$i]);} 我想是不是有办法让PHPLIB只解析模板 但不输出结果 直接放到变量里呢?里面不是有一个get_var()函数吗?用这个可以取得解析后的模版。 $html = $tpl->parse("out","view");这样就不会被输出了呀 内容会存入$html里了 相当奇怪,php_uploadprogress.dll 找不到指定的程序 如何配置wamp服务器 使用smarty进行整体控制问题 php 怎样实现点击一下图片就会换成另一张图片,图片的个数是3个。 Apache、PHP、SOAP怎样配合工作 PHP获取URL跳转后的链接 请教关于mail() php4.2.3后的session写法是这样的吗? 我的php好像不能注册session? 如何升级PHP?我从406升级到412,就出错了。 这段代码在我本机的apache下运行即可用,可我传到服务器上后就不好用了为什么呢? 关于INI_SET函数
一、修改template.inc
加入以下的几个函数:
/******************************************************************************
函数:savetofile ($dir,$varname)
功能:将分析结果保存到文件中去
参数:$dir,$varname 文件路径,分析结果
*/
function savetofile ($dir,$varname){
$data=$this->finish($this->get_var($varname));
$fp = fopen($dir,"w+");
fwrite($fp,$data);
}
/******************************************************************************
函数:renew ()
功能:清除已赋值数组,以免批生成文件的时候变量之间相互影响
参数:无
*/
function renew(){
$this->varkeys = array();
$this->varvals = array();
//$this->file = array();
}二、生成静态文件过程(仅供参考)
function staticInfo($aid){
global $db,$tbl,$template,$fpath,$file;
$sql="SELECT title,content,hits,title_name,come_from,writer,datetime FROM $tbl where news_id=$aid";
$db->query($sql);
$db->next_record();
//取出数据
$template->set_var(array("content" => $db->f("content"),"title" => $db->f("title"),"datetime" => $db->f("datetime"),"writer" => $db->f("writer"),"come_from" => $db->f("come_from")));
$template->parse("mains",$file);
//把分析结果mains存入静态文件
$filename = ARTICLE_PATH.$fpath."/".srandnum().time().".htm";
$template->savetofile("../".$filename,"mains");
echo $filename."<br>";
//置空
$template->renew();
//把旧文件删除,新文件路径保存到数据库
$sql = "select filepath from $tbl where news_id=$aid and checked=1";
if($db->query($sql)){
$db->next_record();
@unlink("../".$db->f("filepath"));
}
//标识为已审核新闻
$sql = "update $tbl set filepath='$filename',checked=1 where news_id=$aid";
$db->query($sql);
}
$newslist = $_POST['fldTblList'];
$id = explode(",",$newslist);for($i=0;$i<count($id);$i++){
staticInfo($id[$i]);
}
里面不是有一个get_var()函数吗?
用这个可以取得解析后的模版。