最新下载
热门教程
- 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 代码
//本文章原创于www.111com.net转载注明出处
相关文章
- 明日方舟界园肉鸽待机缘有什么用 历钱通宝待机缘效果 08-06
- 大侠立志传被围攻的山贼事件流程攻略 08-06
- 燕云十六声缺口袋把戏团无伤怎么过 鬼神愁无伤逃课打法 08-06
- win11网络连接不见了怎么解决 08-06
- 《QQ》小世界删除推过方法 08-06
- W3 Total Cache Pro v2.8.11 汉化版 WordPress 缓存插件 08-06