for most of my templating I simply make php files that are nothing but html with php variables placed into them at the right spots. Then I set up the variables and include the template.
However once in a while this falls short as I want to put the html into a variable, mainly for building tables or sending email, in that case I've come up with a very simple solution that allows me to do almost the same thing.
I put this function
<?php
function parse_template($filename) {
$template_contents = "";
if(!file_exists($filename)) {die("Template ($filename) does note exist.");}
if(!$fp = fopen($filename,'r')) {die("Could not open template ($filename).");}
$lines = file($filename);
//the following two lines are split for *nix and windows compatibility
$globals = rtrim(array_shift($lines),"\r"):
$globals = rtrim($globals,"\n");
$globals = split(",",$globals);
foreach ($globals as $gbl) {global $$gbl;}
$template_contents = implode("",$lines);
$template_contents = preg_replace("/\[(\w+)\]/e","\$\$1",$template_contents);
return $template_contents;
} //end parse_template
?>
then I create an html template with a comma seperated list of the variables that template uses as the first line. In the script I make sure that the appropriate globals are setup then I call this function with the path to the file I want to use a template and it returns the parsed html code. This function is in my globals.php file which is included in everyother file on my site.