#20392 [Opn->Bgs]: HTML_Template_IT error with $ in values
| From: | nicos@php.net | Date: | Fri, 15 Nov 2002 02:06:08 +0000 |
| Subject: | #20392 [Opn->Bgs]: HTML_Template_IT error with $ in values | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-10814@lists.php.net to get a copy of this message | ||
ID: 20392
Updated by: nicos@php.net
Reported By: olonoh@yahoo.com
-Status: Open
+Status: Bogus
Bug Type: PEAR related
Operating System: Linux
PHP Version: 4.2.2
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Previous Comments:
------------------------------------------------------------------------
[2002-11-14 19:34:23] jon@jellybob.co.uk
Isn't this the expected behaviour? It's certainly what would happen if
used $whatever in a string anywhere else in PHP - I think people would
just get confused if their variables suddenly disappeared.
If you want to include a $ sign in the string, you need to escape it
(\$).
------------------------------------------------------------------------
[2002-11-12 09:51:43] derick@php.net
recategorize
------------------------------------------------------------------------
[2002-11-12 09:40:42] olonoh@yahoo.com
When an IT variable is set with "$" in the value, the value isn't taken
literally. Example:
<?php
require_once('HTML/IT.php');
$t = new IntegratedTemplate;
$t->setTemplate('{x}', TRUE, TRUE);
$t->setVariable('x', 'I have $1 in my pocket');
$t->show();
?>
The above prints "I have in my pocket".
A solution would be to use str_replace() instead of preg_replace() when
substituting the value. Patch is below:
--- /usr/local/lib/php/HTML/IT.php 2002-10-14 12:05:57.000000000
-0500
+++ /usr/local/lib/php/HTML/IT.php 2002-11-04 11:11:31.000000000
-0500
@@ -414,7 +414,7 @@
if ($this->clearCacheOnParse) {
foreach ($this->variableCache as $name => $value) {
- $regs[] = "@" . $this->openingDelimiter . $name .
$this->closingDelimiter . "@";
+ $regs[] = $this->openingDelimiter . $name .
$this->closingDelimiter;
$values[] = $value;
}
$this->variableCache = array();
@@ -424,7 +424,7 @@
foreach ($this->blockvariables[$block] as $allowedvar =>
$v) {
if (isset($this->variableCache[$allowedvar])) {
- $regs[] = "@".$this->openingDelimiter .
$allowedvar . $this->closingDelimiter . "@";
+ $regs[] = $this->openingDelimiter . $allowedvar .
$this->closingDelimiter;
$values[] = $this->variableCache[$allowedvar];
unset($this->variableCache[$allowedvar]);
}
@@ -433,7 +433,7 @@
}
- $outer = (0 == count($regs)) ? $this->blocklist[$block] :
preg_replace($regs, $values, $this->blocklist[$block]);
+ $outer = (0 == count($regs)) ? $this->blocklist[$block] :
str_replace($regs, $values, $this->blocklist[$block]);
$empty = (0 == count($values)) ? true : false;
if (isset($this->blockinner[$block])) {
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20392&edit=1