php Http_Template_IT類庫進(jìn)行模板替換
更新時間:2009年03月19日 01:29:44 作者:
php Http_Template_IT模板替換實(shí)現(xiàn)代碼
兩個簡單模板:
<html>
<head>
<title>{title}</title>
</head>
<body>
<font color=red size=6><center>{title}</center></font>
<hr>
<pre>{body}</pre>
</body>
</html>
<html>
<head>
<title>{title}</title>
</head>
<body>
<font color=green size=7><center>{title}</center></font>
<pre>{body}</pre>
</body>
</html>
必須先安裝Http_Template_IT類庫
<?php
require_once "HTML/Template/IT.php";
//創(chuàng)建新的HTML_Template_IT對象,其中參數(shù)為模版文件所在路徑
$template = new HTML_Template_IT('templates/');
//讀取模版文件,通過讀取地址欄上的參數(shù)獲得模版信息
$template->loadTemplateFile($_GET['template'].".htm");
//設(shè)置模版中的參數(shù)
$template->setVariable('title', 'HTML_Template_IT');
$template->setVariable('body', 'Hello World');
//顯示頁面
$template->show();
?>
在瀏覽器中寫入如下,會發(fā)現(xiàn)模板替換效果:
http://localhost:8082/file:/F:/php/phpcode/23/23.4.3/23.4.3.php?template=T2
http://localhost:8082/file:/F:/php/phpcode/23/23.4.3/23.4.3.php?template=T1
復(fù)制代碼 代碼如下:
<html>
<head>
<title>{title}</title>
</head>
<body>
<font color=red size=6><center>{title}</center></font>
<hr>
<pre>{body}</pre>
</body>
</html>
復(fù)制代碼 代碼如下:
<html>
<head>
<title>{title}</title>
</head>
<body>
<font color=green size=7><center>{title}</center></font>
<pre>{body}</pre>
</body>
</html>
必須先安裝Http_Template_IT類庫
復(fù)制代碼 代碼如下:
<?php
require_once "HTML/Template/IT.php";
//創(chuàng)建新的HTML_Template_IT對象,其中參數(shù)為模版文件所在路徑
$template = new HTML_Template_IT('templates/');
//讀取模版文件,通過讀取地址欄上的參數(shù)獲得模版信息
$template->loadTemplateFile($_GET['template'].".htm");
//設(shè)置模版中的參數(shù)
$template->setVariable('title', 'HTML_Template_IT');
$template->setVariable('body', 'Hello World');
//顯示頁面
$template->show();
?>
在瀏覽器中寫入如下,會發(fā)現(xiàn)模板替換效果:
http://localhost:8082/file:/F:/php/phpcode/23/23.4.3/23.4.3.php?template=T2
http://localhost:8082/file:/F:/php/phpcode/23/23.4.3/23.4.3.php?template=T1
相關(guān)文章
需要使用php模板的朋友必看的很多個頂級PHP模板引擎比較分析
最近學(xué)習(xí)php模板技術(shù),找到一篇不錯的關(guān)于php模板的分析為了找到一個好的模板引擎,我在互聯(lián)網(wǎng)上進(jìn)行搜索,目前已經(jīng)整理出了以下名單2008-05-05ThinkPHP關(guān)聯(lián)模型操作實(shí)例分析
ThinkPHP關(guān)聯(lián)模型操作實(shí)例分析,需要的朋友可以參考下2012-09-09PHP簡單系統(tǒng)數(shù)據(jù)添加以及數(shù)據(jù)刪除模塊源文件下載
今天我們總結(jié)一下PHP簡單信息系統(tǒng)MySQL中數(shù)據(jù)添加模塊以及刪除模塊的學(xué)習(xí)內(nèi)容。2008-06-06php smarty截取中文字符亂碼問題?gb2312/utf-8
一般網(wǎng)站頁面的顯示都不可避免的會涉及子字符串的截取,這個時候truncate就派上用場了,但是它只適合英文用戶,對與中文用戶來說,使用 truncate會出現(xiàn)亂碼2011-11-11