欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

用Smarty生成 静态文件的有关问题

程序员文章站 2022-05-11 17:55:20
...
用Smarty生成 静态文件的问题?
require( "../inc/fuction.php ");
require( "../inc/inc.php ");
require( "../inc/db.php ");
require ( "../Smarty/Smarty.class.php ");

$id=$_GET[ 'id '];
if(isset($id)&&is_numeric($id))
{
$db=new F2MysqlClass($dbhost, $dbuser, $dbpw, $dbname);
$sql= "select * from news where id= '$id ' ";
$result=$db-> fetchArray($db-> query($sql));
$tmp=new Smarty;

$tmp-> template_dir = "../smarty/templates/templates ";
$tmp-> compile_dir = "../smarty/templates/templates_c ";
$tmp-> config_dir = "../smarty/templates/config ";
$tmp-> cache_dir = "../smarty/templates/cache ";

if(!empty($result))
{
$tmp-> assign(array(
"title ",htmlspecialchars($result[ "title "]),
"Name ",$result[ "author "]));
}
$tmp-> display( 'index.tpl ');
$this_my_f= ob_get_contents(); //此处关键
ob_end_clean();
$filename = "$id.html ";
if(tohtmlfile_cjjer($filename,$this_my_f))
echo "生成成功 $filename ";
else
echo "生成识别 ";

}

//把生成文件的过程写出函数
function tohtmlfile_cjjer($file_cjjer_name,$file_cjjer_content)
{
if (is_file ($file_cjjer_name)){
@unlink ($file_cjjer_name);
}
$cjjer_handle = fopen ($file_cjjer_name, "w ");
if (!is_writable ($file_cjjer_name)){
return false;
}
if (!fwrite ($cjjer_handle,$file_cjjer_content)){
return false;
}
fclose ($cjjer_handle); //关闭指针
return $file_cjjer_name;
}

文件可以生成。但是生成的文件里的标签没替换?标签的地方显示的全是空白。什么问题?

------解决方案--------------------
怀疑赋值有问题
用Smarty生成 静态文件的有关问题

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频