<?
/*
this is my easy parser class
by derana2k3
http://www.darksummer.de
*/
class tpl{
var $template_file;
var $replace_array;
var $contentTemplate;
var $delimiterStart = "{";
var $delimiterEnd = "}";
/*
set a new start delimiter
*/
function setStartDelim($delim="{")
{
$this->delimiterStart = $delim;
}
/*
set a new end delimiter
*/
function setEndDelim($delim="}")
{
$this->delimiterEnd = $delim;
}
/*
loads the template file
*/
function tpl($template_file)
{
if(file_exists($template_file))
{
$this->template_file = file($template_file);
return $this->template_file;
}
else
{
$this->template_file = "";
die("failed to load template file");
}
}
function assign($searchString,$key=false)
{
if(is_array($searchString))
{
foreach($searchString as $var => $key)
{
$search = $this->delimiterStart.$var.$this->delimiterEnd;
$replace = $key;
$this->template_file = str_replace($search,$replace,$this->template_file);
}
}
else
{
$search = $this->delimiterStart.$searchString.$this->delimiterEnd;
$replace = $key;
$this->template_file = str_replace($search,$replace,$this->template_file);
}
return $this->template_file;
}
}
function out()
{
echo(implode("", $this->template_file));
}
};
?>