用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;
}
文件可以生成。但是生成的文件里的标签没替换?标签的地方显示的全是空白。什么问题?
------解决方案--------------------
怀疑赋值有问题
0
0
相关文章
ini_set()在PHP中的作用是什么?
在PHP中的readlink()函数
我们如何编写PHP脚本来释放与MySQL结果关联的游标内存?
PHP intdiv() 函数
我们如何使用PHP脚本删除MySQL数据库?
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
void是一元运算符,执行右侧表达式但始终返回undefined;用于丢弃返回值、阻止a标签跳转、IIFE忽略结果、动态导入不取Promise、安全获取undefined。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。
1
2025.12.29
调整VSCode界面字体大小可通过设置编辑器或整体UI缩放实现;2.修改"Editor:FontSize"改变代码字体;3.设置"Window:ZoomLevel"调整整体界面字体;4.使用Ctrl+滚轮快捷键临时缩放。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。
1
2025.12.29
单行注释快捷键为Ctrl+/(Windows/Linux)或Cmd+/(macOS),块注释使用Shift+Alt+A(Windows/Linux)或Shift+Option+A(macOS),VSCode会根据语言类型自动匹配语法,如JavaScript用//,Python用#,C++用//,若快捷键无效需检查语言扩展或插件冲突。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。
1
2025.12.29
本专题系统讲解 Golang 在命令行工具(CLI)开发中的实战应用,内容涵盖参数解析、子命令设计、配置文件读取、日志输出、错误处理、跨平台编译以及常用CLI库(如 Cobra、Viper)的使用方法。通过完整案例,帮助学习者掌握 使用 Go 构建专业级命令行工具与开发辅助程序的能力。
4
2025.12.29
热门下载
相关下载
精品课程
最新文章





