Re: [phplib] template class 1.5 bug - removes $[0-9] From: Ben Curtis (benc <email protected>)
Date: 06/21/01

Recently someone suggested changing the $ to the html entity equivalent to avoid the pcre match, then reverting it back to a $ in finish(). Here's the patch I use to do that and it seems to fix the problem for me. Yeah, it's a work-around, but it gets the job done.

On Wed, Jun 20, 2001 at 07:55:49PM -0500, Layne Weathers wrote:
> I recall skimming over comments on this thread recently, but did not pay
> attention to it at the time. I searched in the archives, but my poor
> searching skills returned nothing so I am posting here. I had reason today
> to find a way to fix the problem and am presenting it here for comment.
>
> I determined that the problem was in preg_replace()'s handling of $ followed
> by a numeral (the way we normally use $) - using $ followed by a letter or a
> space (and presumably any other non-numeral character) does not cause a
> problem. I was not satisfied with the workaround of inserting a space
> because I, as well as the other users of my site, am not apt to recall that
> workaround every time I post dollar amounts to a page.
>
> In Template::set_var(), I replaced
> $this->varvals[$varname] = $value;
> with
> $value = ereg_replace('\$([0-9])', '\$\\\1', $value);
> $this->varvals[$varname] = $value;
> and
> $this->varvals[$k] = $v;
> with
> $v = ereg_replace('\$([0-9])', '\$\\1', $v);
> $this->varvals[$k] = $v;
>
> Then in Template::finish(), I added
> $str = str_replace('\$0', '$0', $str);
> $str = str_replace('\$1', '$1', $str);
> $str = str_replace('\$2', '$2', $str);
> $str = str_replace('\$3', '$3', $str);
> $str = str_replace('\$4', '$4', $str);
> $str = str_replace('\$5', '$5', $str);
> $str = str_replace('\$6', '$6', $str);
> $str = str_replace('\$7', '$7', $str);
> $str = str_replace('\$8', '$8', $str);
> $str = str_replace('\$9', '$9', $str);
> right before
> return $str;
>
> I tried to do this with a regular expression*, but the result came out '\$'
> instead of '$'. I'm not familiar with PCRE, and probably only barely past
> beginner familiarity with the POSIX regexs. Any regex that accomplishes the
> same as above (and works the same within the Template class) would be
> appreciated. Any comments on my solution, including unexpected (by me)
> surprises that it may cause, are appreciated - I've made minor changes to
> the template class before, but have always been intimidated by the
> substitution methods it uses.
>
> * $str = ereg_replace('\\\$([0-9])', '\$\1', $str);
>
>
> Layne Weathers
> Ifworld, Inc.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: phplib-unsubscribe <email protected>
> For additional commands, e-mail: phplib-help <email protected>

-- 
My pid is Inigo Montoya. You killed -9 my parent process. Prepare to vi.

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>