I used file_get_contents and str_ireplace, something I made a bit ago. First functions before the actual class were things that might be useful to you, required some defined constants though.
function showHeader()
{
include(TEMPLATE."header".TEMPLATE_EXT);
return;
}
function showFooter()
{
include(TEMPLATE."footer".TEMPLATE_EXT);
return;
}
/**
* Takes an error message, displays it through the error.php template, then calls the footer
* and kills the script with exit().
*
* @param string $errorMessage Error message you want the user to see.
*/
function showError($errorMessage)
{
$template = new template("error");
$template->fillBraces(array(
"ERROR_MESSAGE" => $errorMessage,
"ERROR_IMG" => IMG_PATH."error.png"));
$template->render();
showFooter();
exit();
return;
}
class template
{
protected $_viewContents;
function __construct($viewName)
{
$this->_viewContents = file_get_contents(TEMPLATE.$viewName.TEMPLATE_EXT);
return;
}
function sourceOf($fileName)
{
return @file_get_contents(TEMPLATE.$fileName.TEMPLATE_EXT);
}
function fillBraces($information, $replacement=NULL)
{
if (is_array($information))
{
foreach ($information as $key => $val)
{
$this->_viewContents = str_ireplace("{".$key."}", $val, $this->_viewContents);
}
return;
} elseif ($replacement!=NULL)
{
$this->_viewContents = str_ireplace("{".$information."}", $replacement, $this->_viewContents);
return;
}
}
function render()
{
echo $this->_viewContents;
return;
}
}
/**
* And finally, the example usage!
* $template = new template("viewthread");
* $template->fillBraces(array(
* "THREAD_TITLE" => "How to bathe your chimpanzee",
* "THREAD_AUTHOR" => "Stuart Piazza"
* ));
* $template->render();
*/