Re: [phplib] Problems with PHP 4.0.4, template.inc, and the modified From: John Mandeville (mandevil <email protected>)
Date: 01/29/01

I don't have the original message to include here. The problem was
with templates changing text from something like "$50.00" to ".00" due
to changes in the Perl-compatible regex engine in PHP 4.0.4.

The original poster had tried escaping with, for example, preg_quote().
 At best, you'll get the backslashes retained in your final html
output, and at worst, you'll screw up template.inc if you do this.
Instead, change dollar signs to "&#36;" entities. But don't fully
entify with htmlentities(), or else you'll lose the braces that
template.inc needs.

The following diff -c on template.inc has, so far as I've tested it
(which isn't much), solved the problem. Your mileage may vary. This
change only entifies a dollar sign when followed by a digit. If you
want template.inc to de-entify the dollar signs before you actually use
the page, add the appropriate ereg_replace line as a new first line to
finish(). The original template.inc in the diff is from version 7.2c.
My admittedly scanty tests were with PHP 4.0.4p1.

Of course, if you use preg_*() functions outside template.inc, you may
problems there, too.

John Mandeville

*** e:template.inc Mon Jan 29 10:34:24 2001
--- template.inc Mon Jan 29 11:47:08 2001
***************
*** 105,110 ****
--- 105,112 ----
  
      $str = $this->get_var($parent);
      $reg = "/<!--\s+BEGIN $handle\s+-->(.*)\n\s*<!--\s+END
$handle\s+-->/sm";
+ // JEM - Added next line.
+ $str = ereg_replace( '\$([0-9])', '&#36;\1', $str );
      preg_match_all($reg, $str, $m);
      $str = preg_replace($reg, "{" . "$name}", $str);
      $this->set_var($handle, $m[1][0]);
***************
*** 122,127 ****
--- 124,131 ----
      if (!is_array($varname)) {
        if (!empty($varname))
          if ($this->debug) print "scalar: set *$varname* to
*$value*<br>\n";
+ // JEM - Added next line.
+ $value = ereg_replace( '\$([0-9])', '&#36;\1', $value );
          $this->varkeys[$varname] = "/".$this->varname($varname)."/";
          $this->varvals[$varname] = $value;
      } else {
***************
*** 129,134 ****
--- 133,140 ----
        while(list($k, $v) = each($varname)) {
          if (!empty($k))
            if ($this->debug) print "array: set *$k* to *$v*<br>\n";
+ // JEM - Added next line.
+ $v = ereg_replace( '\$([0-9])', '&#36;\1', $v );
            $this->varkeys[$k] = "/".$this->varname($k)."/";
            $this->varvals[$k] = $v;
        }

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