public function replace($string, $escape_mode = '')
{
$this->escape_mode = $escape_mode;
// replace strings like this: {tagname attr="value"}
$string = preg_replace_callback('/\\{(\\w+)(\\ +(?:(?!\\{)[^}\\n])+)*\\}/', array($this, 'replace_tag'), $string);
// call again to take care of nested variables
$string = preg_replace_callback('/\\{(\\w+)(\\ +(?:(?!\\{)[^}\\n])+)*\\}/', array($this, 'replace_tag'), $string);
return $string;
}