欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php Http_Template_IT类库进行模板替换

程序员文章站 2023-09-08 22:58:09
两个简单模板:复制代码 代码如下: {title}
两个简单模板:
复制代码 代码如下:

<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