#21287 [Opn->Bgs]: str_replace behaves strangely, not replacing valid key/val pairs
| From: | black@php.net | Date: | Mon, 30 Dec 2002 21:35:59 +0000 |
| Subject: | #21287 [Opn->Bgs]: str_replace behaves strangely, not replacing valid key/val pairs | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-28794@lists.php.net to get a copy of this message | ||
ID: 21287
Updated by: black@php.net
Reported By: tit.petric@telemach.net
-Status: Open
+Status: Bogus
Bug Type: *General Issues
Operating System: linux debian
-PHP Version: 4.2.3
+PHP Version: 4.3
New Comment:
it appears i had a nested template to replace a key, after the
key/value pairs were substituted already - thus resulting in that
little error
totally my fault, seems that most of my bugs are :P
Previous Comments:
------------------------------------------------------------------------
[2002-12-30 10:56:59] tit.petric@telemach.net
behaviour confirmed also on 4.3
http://sunshine.krneki.org/phpinfo.php
i've tried the script with and without the phpA zend_extension, and if
it was active then i tried it in disabled mode (php_value phpa off -
inside .htaccess)
currentlly the php.ini file is the same as php.ini-recommended inside
the 4.3.0 distribution
i now definetly check if i str_replace that key inside the first loop
and the logging is as follows (same as before):
(1.228) 0.0028 replace block_spacing_height => <img
src="modules/themes/base/images/pixel.gif" align="middle" border="0"
alt="" height="10">
(1.232) 0.0040 block_spacing_height exists in parsevals?!?!?
(1.233) 0.0017 Undefined variables exist in root (site_footer.tpl):
Array
(
[0] => Array
(
[0] => {block_spacing_height}
)
)
ofcourse after the repeated str_replace the key is accurately replaced
so i dont know where the problem could live (if its on my side)...
is there any way i can track this more accuratelly than with my own
functions? debug_backtrace() perhaps?
------------------------------------------------------------------------
[2002-12-30 06:00:42] tit.petric@telemach.net
i have a template engine running, in it a string (content hereon) with
keys and an array (parsevals hereon) with key/values that need to be
replaced in the content
this is what i do:
foreach ($this->_parsevals as $key=>$val) {
$retval = str_replace('{'.$key.'}',$val,$retval);
}
after that i do a preg_match_all to find all the remaining keys in the
content with this regexp: '/\{[A-Za-z][-_A-Za-z0-9]*\}/', and find
existing keys, which also exist in $this->_parsevals..
if (preg_match_all($this->regex_var,$retval,$result)) {
foreach ($result[0] as $val) {
$key = substr($val,1,-1);
if (isset($this->_parsevals[$key])) {
condor_assert($key." exists in
parsevals?!?!?");
$retval = str_replace($val,
$this->_parsevals[$key],$retval);
}
}
}
condor_assert is a basic log function, and its activated with that
error message in there... another str_replace seems to solve the
problem of the "undefined variable" case..
i tried to reproduce this in a short-self-contained script but failed,
i will test it on 4.3 asap
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=21287&edit=1