最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php Http_Template_IT类库进行模板替换
时间:2023-10-20 09:53:58 编辑:袖梨 来源:一聚教程网
php Http_Template_IT模板替换实现代码
两个简单模板:
代码如下:
<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";
//创建新的HTML_Template_IT对象,其中参数为模版文件所在路径
$template = new HTML_Template_IT('templates/');
//读取模版文件,通过读取地址栏上的参数获得模版信息
$template->loadTemplateFile($_GET['template'].".htm");
//设置模版中的参数
$template->setVariable('title', 'HTML_Template_IT');
$template->setVariable('body', 'Hello World');
//显示页面
$template->show();
?>
在浏览器中写入如下,会发现模板替换效果:
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
相关文章
- 苏丹的游戏部队获得途径 07-05
- 苏丹的游戏全部奇珍获取方式 07-05
- 金铲铲之战s14堡垒执事阵容攻略 07-05
- SATS价值币是什么?在2025年SATS币上涨空间大嘛? 07-05
- 燕云十六声我即是江湖称号怎么获得 07-05
- 崩坏星穹铁道3.2全追忆残像收集攻略 07-05