PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_Template_IT » Bug #2040

$n in variable values swallowed

Details

Submitted2004-08-01 17:55 UTC
Fromhgs at cs dot columbia dot edu
Assignedpajoye
StatusBogus
PackageHTML_Template_IT
PHP Version4.3.8
OSn/a
Roadmaps(Not assigned)

Comments

[2004-08-01 17:55 UTC] hgs at cs dot columbia dot edu

Description:
------------
1.3 2003/03/12

If the substitution text includes $n (e.g., $1), the $n part will be swallowed since preg_replace interprets this as the replacement character. Using str_replace works fine.

This is reported in Bug #50 as not a bug - but the behavior is completely non-obvious and completely non-documented. There does not appear to be a legitimate use for the $n behavior in this package. At the least, this should be documented rather than the poor programmer having to guess that preg_replace is used and that this isn't being escaped.

Reproduce code:
---------------
setlocale(LC_MONETARY, 'en_US');
$v['element'] = '$1,448.00';
$t = new HTML_Template_IT();
$t->setOptions(array('use_preg' => false));
$t->setTemplate("an {element} template");
$t->setVariable($v);
echo $t->get();

Expected result:
----------------
$1,448

Actual result:
--------------
,448

[2004-08-06 12:45 UTC] pierre at dotgeek dot org

Cannot reproduce, works as expected (output $1448.00).

--Pierre

[2004-08-09 03:04 UTC] hgs at cs dot columbia dot edu

Sorry, my confusion. It works fine with use_preg=>false, but fails with use_preg=>true. The string matching algorithm, particularly since this "feature" is undocumented and serves no useful purpose, shouldn't matter, but it does.

See https://mice.cs.columbia.edu/test/moneyformat.php for the example.