Home » HTML » HTML_Template_IT » Bug #3686
Wrong parsing with \ in values
Details
| Submitted | 2005-03-03 10:50 UTC |
|---|---|
| From | marco at alphasoft dot ch |
| Assigned | pajoye |
| Status | Bogus |
| Package | HTML_Template_IT |
| PHP Version | 4.3.10 |
| OS | Windows |
| Roadmaps | (Not assigned) |
Comments
[2005-03-03 10:50 UTC] marco at alphasoft dot ch
Description:
------------
If there are \ in the values, the rest will be skipped.
The problem is, that the function preg_replace needs additional slashes for \
Reproduce code:
---------------
$tpl = new HTML_Template_IT(_TEMPLATE_DIR);
$tpl->loadTemplatefile('test.html',false);
$tpl->setVariable('TEST','test\\17');
$tpl->parse();
ob_start('ob_gzhandler');
$str = $tpl->get();
echo $str;
Expected result:
----------------
test\17
Actual result:
--------------
test
[2005-03-03 11:08 UTC] pierre at dotgeek dot org
Use str_replace mode. The default uses preg, this string are used by regexp.
See setOptions, or pass the option to the constructor:
array('use_preg'=>false)
--Pierre
[2006-04-03 10:12 UTC] info at der-dirigent dot de
hello,
i have not the problem, that the rest will be skipped. only the slashes self will skipped. for example:
'\\\\\\\\\\\'' the result should be \\\\\' but it is \'
or this '\\\'' should be convert to \' but i get only this '
if i set use_preg to false '\\\\\\\\\\\'' => \\' this is wrong too. i think.
[2006-04-03 15:29 UTC] info at der-dirigent dot de
ok, i think it's the same problem like this one. http://pear.php.net/bugs/bug.php?id=7179
i dont' find any solution :-(
addslashes don't work and array('use_preg'=>false) is wrong too. i will be very happy if you can help me.
[2006-06-13 17:17 UTC] leonard-php-bugzilla at ottolander dot nl
$ cat test.htmpl
<html>
<body>
{DATA1}<br>
{DATA2}<br>
{DATA3}<br>
</body>
</html>
$cat testit.php
<?php
define('BR', "<br>\n");
require_once('HTML/Template/IT.php');
$tpl_main = new HTML_Template_IT('.');
$tpl_main->loadTemplateFile('test.htmpl', true, true);
$data1 = "\\\\\\\\\\'"; // 5 backslashes and a single quote
$data2 = addslashes($data1); // will also escape quotes
// only escaping backslashes gives the desired result
$data3 = preg_replace('/(\\\\)/', "\\\\\\\\", $data1);
echo $data1 . BR;
echo $data2 . BR;
echo $data3 . BR;
$tpl_main->setVariable('DATA1', $data1);
$tpl_main->setVariable('DATA2', $data2);
$tpl_main->setVariable('DATA3', $data3);
$tpl_main->show();
?>
[2006-06-13 19:23 UTC] leonard-php-bugs at ottolander dot nl
What I try to show with the addslashes vs. the preg expression is that one needs to only escape (double) the backslashes (not the quotes) to get the correct result (the first echo and the last setVariable show the same result). (Replying to the comments of Paul Eppner, being fully aware this is OT for this bug report, but you asked for it ;) (an example) .)
But then all this is mute as creating the template with use_preg set to false indeed gives the expected result. Thanks for this information. Sadly I could not find any mention of use_preg in the PEAR manual (try a google on site:http://pear.php.net/manual/en/ use_preg and see there are zero results). Maybe this can be added to the documentation?