Re: [Phplib-users] comments in template file
Brought to you by:
nhruby,
richardarcher
From: Sven <Sv...@Ko...> - 2003-04-11 11:39:19
|
> Give it an easy way to delete comments in a template file so that the > output not have the comments? I need it now and have make this: In template.inc at the end a new function: /****************************************************************************** * This function strip comments from templates. * * Returns: * * @param $str * @access public * @return string */ function delete_comment($str) { if ($this->debug & 1) { print("<b>Varname:</b> $str<br>\n"); } $left_delimiter = '{*'; $right_delimiter = '*}'; // Quote regular expression characters $ldq = preg_quote($left_delimiter, '!'); $rdq = preg_quote($right_delimiter, '!'); $str = preg_replace("!$ldq(.*?)$rdq!se", "", $str); return $str; } Its not the best, but it works. And i have write it in the finish function: function finish($str) { switch ($this->unknowns) { case "keep": $str = $this->delete_comment($str); break; case "remove": $str = preg_replace('/{[^ \t\r\n}]+}/', "", $str); $str = $this->delete_comment($str); break; case "comment": $str = preg_replace('/{([^ \t\r\n}]+)}/', "<!-- Template variable \\1 undefined -->", $str); $str = $this->delete_comment($str); break; } return $str; } Better ideas are welcome (-; -- Ciao Sven --------- http://www.amazon.de/exec/obidos/wishlist/8WTO0DD0O1NY pgpid: 0xF74A4663 434D C7A5 C4D6 01F9 88F6 59B3 381D B526 F74A 4663 |