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 Http_Template_IT類庫進(jìn)行模板替換
php Http_Template_IT模板替換實(shí)現(xiàn)代碼2009-03-03

