在网上下载phplib template,在其中找到template.inc单独复制出来导入我们的php文件中就可以使用phplib template
t.php
include ("template.inc");
$t = new template(".", "keep");
$t->set_file("gg", "gg.html");
$t->set_var("title","good boy!");
$t->parse("ggp","gg");
$t->p("ggp");
?>
gg.html
-----------
{name}
-----------
运行t.php可以看到{title}被替换为good boy!
t.php
include ("template.inc");
$t = new template(".", "keep");
$t->set_file("gg", "gg.html");
$t->set_var("title","good boy!");
$t->set_block("gg", "li", "nli");
$t->set_var("name", "xiaoming");
$t->parse("nli", "li", true);
$t->parse("ggp","gg");
$t->p("ggp");
?>
gg.html
-----------
{name}
-----------
运行t.php可以看到{name}被替换为xiaoming
t.php
t.php
include ("template.inc");
$t = new template(".", "keep");
$t->set_file("gg", "gg.html");
$t->set_file("h", "header.html");
$t->parse("header", "h");
$t->set_file("f", "footer.html");
$t->parse("footer","f");
$t->parse("ggp","gg");
$t->p("ggp");
?>
header.html
xiaoming is a header
footer.html
xiaoyang is a footer
gg.html