Re: Play nice! Re: Savant/Flexy/Foo template engines
| From: | Paul M Jones | Date: | Thu, 10 Jun 2004 19:07:52 +0000 |
| Subject: | Re: Play nice! Re: Savant/Flexy/Foo template engines | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-30418@lists.php.net to get a copy of this message | ||
Sorry to keep replying to myself about the filters thing.
Smarty has this little goodie as an output filter, and it's definitely more than just a regex: function smarty_outputfilter_trimwhitespace($source, &$smarty) {... might use str_replace, too, for speed, or ereg (for whatever reason).I think that's exactly what they are. Is that bad? How else is one to implement an output filter? Yes, streams allow you to register filtering functions, but not everybody knows streams that well (I sure don't :-).* An extended toString() seems the logical place for output filters to be applied.I'm still not convinced that output filters are anything more that preg_replaces on the output to toString.. -
// Pull out the script blocks
preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);
$_script_blocks = $match[0];
$source = preg_replace("!<script[^>]+>.*?</script>!is",
'@@@SMARTY:TRIM:SCRIPT@@@', $source);
// Pull out the pre blocks
preg_match_all("!<pre>.*?</pre>!is", $source, $match);
$_pre_blocks = $match[0];
$source = preg_replace("!<pre>.*?</pre>!is",
'@@@SMARTY:TRIM:PRE@@@', $source);
// Pull out the textarea blocks
preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match);
$_textarea_blocks = $match[0];
$source = preg_replace("!<textarea[^>]+>.*?</textarea>!is",
'@@@SMARTY:TRIM:TEXTAREA@@@', $source);
// remove all leading spaces, tabs and carriage returns NOT
// preceeded by a php close tag.
$source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source));
// replace script blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);
// replace pre blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source);
// replace textarea blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);
return $source;} function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {
$_len = strlen($search_str);
$_pos = 0;
for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)
if (($_pos=strpos($subject, $search_str, $_pos))!==false)
$subject = substr_replace($subject, $replace[$_i], $_pos, $_len);
else
break;
}
--
Paul M. Jones
Savant: the simple alternative to Smarty for PHP.
http://phpsavant.com/
DB_Table: build RDBMS tables and XHTML forms in one PHP class.
http://wiki.ciaweb.net/yawiki/index.php?area=DB_Table
Yawiki: your collaborative online documentation system.
http://yawiki.com/
Yawp: a single-file foundation for PHP applications.
http://phpyawp.com/