Re: [SMARTY] prefilter problems. More INFO
| From: | Oscar Fernandez Sierra | Date: | Sun, 14 Jul 2002 15:33:09 +0000 |
| Subject: | Re: [SMARTY] prefilter problems. More INFO | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5290@lists.php.net to get a copy of this message | ||
Apart the problem you tell, I think the regular expression you are using aren't the
most adequated, because, in is operating in a greeedy way. Then can work in the right
way sometimes (if you have only a ">" per line), but it isn't the case of your
example
Doing
preg_replace("/<a href=.*>/","",$source);
would "eat" the whole line
<a href="http://www.yahoo.com">Yahoo!</a><br>
You can check that executing the next script
---------------------------------------------------------
<?php
$source = ' <html>
> <body>
> <a
> href="http://www.yahoo.com">Yahoo!</a><br>
> <a
> href="http://www.google.com">google</a><br>
> <a
> href="http://www.php.net">PHP</a><br>
> <a
> href="http://www.linux.com">Linux</a><br>
> <a
> href="http://slashdot.org">slashdot</a><br>
> </body>
> </html>';
# Uncomment just one of the two next lines
####$source = preg_replace("/<a href=.*>/","",$source); # Default: greedy
match: .*
$source = preg_replace("/<a href=.*?>/","",$source); # Non greedy
match: .*?
print $source;
# Its is better change the delimiters to # instead of /, so you don't have
# to escape the "/" in </xxxx> tags, URLs, etc.
### $source = preg_replace("#</a>#","",$source);
?>
-------------------------------------------------------------
Joe Rice wrote:
>
> Hi,
> in an attempt to solve this problem i wrote a php
> script that just creates the smarty instant, defines
> the prefilter function, registers the prefilter, and
> displays the template. the template is just a few
> lines of html which include 5 href tags. the prefilter
> worked the first time around but not after. so, i added
> clear_cache and it still no longer works.
>
> again, any help would be appreciated.
> thanks,
> joe
>
> ---test.php---
> <?php
> define("SMARTY_DIR","/usr/local/lib/php/Smarty/");
> require_once(SMARTY_DIR."Smarty.class.php");
> $t = new Smarty;
>
> function removehref($source) {
> $source = preg_replace("/<a href=.*>/","",$source);
> $source = preg_replace("/<\/a>/","",$source);
> echo "HELLO";
> return $source;
> }
> $t->clear_cache("fullofhref.tpl");
> $t->register_prefilter("removehref",&$t);
> $t->display("fullofhref.tpl");
> ?>
> ------------
> ----fullofhref.tpl---
> <html>
> <body>
> <a
> href="http://www.yahoo.com">Yahoo!</a><br>
> <a
> href="http://www.google.com">google</a><br>
> <a
> href="http://www.php.net">PHP</a><br>
> <a
> href="http://www.linux.com">Linux</a><br>
> <a
> href="http://slashdot.org">slashdot</a><br>
> </body>
> </html>
> --------------------
>
> Joe Rice(riceja@water-melon.net)@Fri, Jul 12, 2002 at 11:19:03PM -0500:
> >
> > I'm using smarty version 1.5.2 and tried to use the
> > example of prefilter form the 1.5.2 smarty manual
> > and it doesn't seem to be working.
> >
> > so, i altered it to fit my needs and it still isn't working.
> >
> > function remove_href($source) {
> > $source = preg_replace("/<a href=.*>/","",$source);
> > $source = preg_replace("/<\/a>/","",$source);
> > echo "HELLO";
> > return $source;
> > }
> >
> >
> > $t->register_prefilter("remove_href");
> > $t->display("email_inbox.tpl");
> >
> > after testing it all my hyper links still work and
> > have the href.
> >
> > and HELLO is never echo'd
> >
> >
> > Any help would be appreciated.
> >
> >
> > thanks,
> > joe
> >
> > --
> > Smarty General Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> --
> How do i get rid of those words in my screen that are coming from you?
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Oscar Fernandez Sierra | Mundinteractivos - El Mundo |
Area de Internet | Pradillo, 42 |
oscar@el-mundo.net | 28002 - Madrid (SPAIN, EU) |
http://www.elmundo.es/ | Tel: (+34) 915864800 (Ext: 4616) |