日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

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

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

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