smarty能创建 php页面,smarty 生成静态html页面
生成靜態頁面,用php生成會比smarty生成要快,但是如果你用smarty模板做的頁面,現在要生成html的話,就可以看看這篇smarty 生成靜態html頁面教程物。<?php
$tpl?=?new?Smarty();
$tpl->template_dir?=?dirname(__FILE__);
$tpl->compile_dir?=?'phprm.com';
$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 代碼
轉載隨意^^請帶上本文地址!
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的smarty能创建 php页面,smarty 生成静态html页面的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 吉利星瑞方向盘原地转动异响?
- 下一篇: php 字符串的比较大小,PHP如何比较