smarty能创建 php页面,smarty 生成静态html页面
生成靜態(tài)頁(yè)面,用php生成會(huì)比smarty生成要快,但是如果你用smarty模板做的頁(yè)面,現(xiàn)在要生成html的話,就可以看看這篇smarty 生成靜態(tài)html頁(yè)面教程物。<?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?生成靜態(tài)html頁(yè)面');
$tpl->assign('content',?'這是文章內(nèi)容');
$content?=?$tpl->fetch($tempFile,?null,?null,?false);
//關(guān)鍵一步就是把?$content生成html?文件就行了,下面來(lái)看
$dir?=?dirname($file);
//目錄不存在就創(chuàng)建
if?(!file_exists($dir))?{
creatDir($dir);
}
$handle?=?fopen($file,?"w+");?//創(chuàng)建文件
if?(!is_writable($file_name))?{?//判斷寫(xiě)權(quán)限
echo?'沒(méi)有寫(xiě)權(quán)限';
}
if?(!fwrite($handle,?$content))?{
echo?'文件不可寫(xiě)';
}
fclose($handle);?//關(guān)閉指針
echo?'生成靜態(tài)頁(yè)面成功';?//返回文件名
function?creatDir($dir)?{
if?(!is_dir($dir))?{
if?(!creatDir(dirname($dir)))?{
return?false;
}
if?(!mkdir($dir,?0777))?{
return?false;
}
}
return?true;
}
//tmplate.tpl 代碼
轉(zhuǎn)載隨意^^請(qǐng)帶上本文地址!
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的smarty能创建 php页面,smarty 生成静态html页面的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 吉利星瑞方向盘原地转动异响?
- 下一篇: php 字符串的比较大小,PHP如何比较