日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

smarty能创建 php页面,smarty 生成静态html页面

發布時間:2024/10/12 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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页面的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。