function Parse() { $content = $this->_template; // Mask {{ and }} for later substitution with { and } $content = str_replace("{{", "_<<<_", $content); $content = str_replace("}}", "_>>>_", $content); // Parse includes $search = "#{INCLUDE}(.*){/INCLUDE}#isU"; preg_match_all($search, $content, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $incfile = dirname($this->_tpl_file) . DIRECTORY_SEPARATOR . $match[1]; $t = new CTemplate($incfile); $t->SetValues($this->_values); $search = sprintf("#{INCLUDE}%s\\{/INCLUDE}#isU", $match[1]); $replace = str_replace("\$", "\\\$", $t->Parse()); $content = preg_replace($search, $replace, $content); } // Replace single fields foreach ($this->_values as $token => $value) { $content = str_replace('{' . $token . '}', $value, $content); } // Replace template blocks foreach ($this->_blockdata as $token => $value) { $content = str_replace('{BLOCK_' . $token . '}', $value, $content); } // Parse PHP if ($this->_parse_php) { $content = $this->_parsePHP($content); } // Strip empty template placeholders if (!$this->_debug) { $content = preg_replace("/{.*}/U", "", $content); } // Now convert the {{ and }} replacements back to { and } $content = str_replace("_<<<_", "{", $content); $content = str_replace("_>>>_", "}", $content); // Return content $this->_content = $content; return $this->_content; }