最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
smarty 生成静态html页面
时间:2022-07-02 10:45:56 编辑:袖梨 来源:一聚教程网
//smarty 下载我主不说了可以到down.111com.net免费下载哦。
$tpl = new Smarty();
$tpl->template_dir = dirname(__FILE__);
$tpl->compile_dir = '111com.net';
$tpl->compile_check = false;//$cfg['debug'];
$tpl->debugging = 0;
$tpl->caching = 0;
$tpl->cache_lifetime = 3600;
$tpl->left_delimiter = '';
//初始化smarty模板
$file = date("Y-m-d").".html";
$tempFile = 'template.tpl';
//解析模板文件
$tpl->assign('title','php smarty 生成静态html页面');
$tpl->assign('content','这是文章内容');
$content=$tpl->fetch($tempFile,null,null,false);
//关键一步就是把 $content生成html 文件就行了,下面来看
$dir = dirname($file);
//目录不存在就创建
if(!file_exists($dir))
{
creatDir($dir);
}
$handle = fopen ($file,"w+"); //创建文件
if (!is_writable ($file_name)){ //判断写权限
echo '没有写权限';
}
if (!fwrite ($handle,$content)){
echo '文件不可写';
}
fclose ($handle); //关闭指针
echo '生成静态页面成功'; //返回文件名
function creatDir($dir)
{
if(!is_dir($dir)){
if(!creatDir(dirname($dir))){
return false;}
if(!mkdir($dir,0777)){
return false;}
}
return true;
}
//tmplate.tpl 代码
//本文章原创于转载注明出处
相关文章
- 雷电模拟器如何设置手机版教程 05-16
- 高德地图导航声音延迟怎么办 05-16
- 什么值得买如何进行意见反馈 05-16
- 微信文件助手网页版如何查看文件上传进度 05-16
- 字体下载为何解码失败 05-16
- cad定距等分怎么操作 05-16