Re: [phplib] php4.0.4 and phplib template problems. From: Padraic Renaghan (list <email protected>)
Date: 01/04/01

* Kartic Krishnamurthy <kaygee <email protected>> [Jan 4 12:12pm]:
> Same case with me..my template driven pages are working fine with php-4.0.4.
> But I tried the specific code posted by Padraic and that was printing 0.50
> instead of $7.50.

I should have also said that all other aspects of templates are
working for me except for the substitution of values that have
"$[0-9]+" like patterns in them.

I tried everywhere between 1 and 5 "\" before the "$" - that didn't
work. I also tried running the value through preg_quote() - that
didn't work. The only workaround I have it to put a space between
the "$" and the number - this results in "$ 7.50" which is Ok for
now, but long-term I really don't want the space.

I figure the right answer is to somehow escape backreferences in
set_var() before the value is loaded into the array. We probably
need to escape both "\1" and "$1" style input since I can't see how
anyone would actually want either of those treated as a
backreference when using templates. I created an escape_var()
function inside the template class, but I the underlying problem in
PHP 4.0.4 seems to be that the escaping of "$1" doesn't seem to
work.

Example:
in set_var()
...
$this->varvals[$varname] = $this->escape_val($value);
...

then
function escape_val($value='') {
  return str_replace ('$', '\$', $value);
}

--
Padraic Renaghan /pad-rik ren-a-han/
padraic <email protected>
AOL IM(gaim): PadraicRenaghan
http://renaghan.com/pcr/

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