yo hice una class bastante sencilla para eso
Código PHP:
<?php
class Template
{
private $_filename = "";
public function __construct($filename)
{
if(file_exists($filename)) {
$this->_filename = $filename;
}else {
throw new Exception("Template no encotrado ( $filename )");
}
}
public function render(array $data = array())
{
if(empty($data)) {
return file_get_contents($this->_filename);
}else {
foreach($data as $key => $value) $$key = $value;
$template = file_get_contents($this->_filename);
$template = str_replace(array('\\', '\''), array('\\\\', '\\\''), $template);
$template = preg_replace('/\{(\w+?)\}/', "'.$$1.'", $template);
eval("\$template = '$template';");
return $template;
}
}
}
para usarla
plantilla.htm
Código PHP:
require_once 'Template.php';
$template = new Template('plantilla.htm');
$datos = array(
'variable' => 'probando plantilla',
);
echo $template->render($datos);
y el resultado
saludos.