I use phplib but it's old and there are people who say there are faster methods.
Simple example from http://www.pcpropertymanager.com/info/index.php and http://www.pcpropertymanager.com/esc/info/index.php
<?php
if (!isset($t))
{
include_once("template.inc");
$t = new Template();
}//end of check for template
$t->set_file( array( "HeadGen" =>"headgen.htm",
"HeadImg" =>"headimg.htm" ));
//set up the variations in my data
include("agentinfo.php");
if (!isset($seDescription))
$seDescription = "Property Management Software. Save yourself time and effort managing your rental investment property. A management and accounting system for residential landlords";
$t->set_var( array("PRODNAME" => $agentvars["prodname"],
"AGENT" => $agentvars["mcname"],
"AGENTCSS" => $agentvars["css"],
"AGENTORDER"=> $agentvars["order"],
"AGENTCONT" => $agentvars["contact"],
"IMGDIR" => $agentvars["imgdir"],
"KEYWORDS" => $keywords,
"AGENTFLAG" => $agentvars["params"],
"AGENTTAG" => $agentvars["dir"],
"ORDERTAG" => $agentvars["order"],
"AGENTDIR" => $agentvars["dir"],
"TITLE" => $title,
"DEMONAME" => $agentvars["demoname"],
"UPGRNAME" => $agentvars["upgrname"],
"STR_HTTP" => $STR_HTTP,
"STR_HTTPS" => $STR_HTTPS,
"SEDESCRIPTION"=> $seDescription
));
$t->parse("Output", "HeadGen");
$t->p ("Output");
$t->parse("Output", "HeadImg");
$t->p ("Output");
?>
then my headgen.html looks like
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- Headgen -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>{PRODNAME} :: {TITLE}</title>
<!-- {SEDESCRIPTION} -->
<meta http-equiv="description" content="{SEDESCRIPTION}">
<meta name="keywords" content="profit, property, investment, apartment, program, rent roll, accounts, free, {KEYWORDS}">
<META NAME="ROBOTS" CONTENT="ALL">
<META HTTP-EQUIV="expires" CONTENT="0">
{AGENTCSS}
<link rel="stylesheet" href="{STR_HTTP}v2/styles/navbuts.css" type="text/css">
<script src="{STR_HTTP}v2/includes/stats4all.js"></script>
<script src="{STR_HTTP}v2/includes/pcpm.js"></script>
<script language="JavaScript">
pcpmPreLoad('{STR_HTTP}v2/images/pcpnav_on.gif');
</script>
{EXTRAHEAD}
</head>