Date: 06/20/01
- Next message: Vladimir: "[phplib] PHP Session"
- Previous message: Philippe Paravicini: "RE: [phplib] phplib and mod_php4"
- Next in thread: Layne Weathers: "Re: [phplib] template class 1.5 bug - removes $[0-9]"
- Maybe reply: Layne Weathers: "Re: [phplib] template class 1.5 bug - removes $[0-9]"
- Reply: Ben Curtis: "Re: [phplib] template class 1.5 bug - removes $[0-9]"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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>
- Next message: Vladimir: "[phplib] PHP Session"
- Previous message: Philippe Paravicini: "RE: [phplib] phplib and mod_php4"
- Next in thread: Layne Weathers: "Re: [phplib] template class 1.5 bug - removes $[0-9]"
- Maybe reply: Layne Weathers: "Re: [phplib] template class 1.5 bug - removes $[0-9]"
- Reply: Ben Curtis: "Re: [phplib] template class 1.5 bug - removes $[0-9]"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

