Bug #18440: str_replace array replace can't handle strings in quotes

From: Date: Fri, 19 Jul 2002 21:35:23 +0000
Subject: Bug #18440: str_replace array replace can't handle strings in quotes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-14659@lists.php.net to get a copy of this message
From: yml@dtlink.com Operating system: Redhat 6.1 PHP version: 4.2.1 PHP Bug Type: Strings related Bug description: str_replace array replace can't handle strings in quotes Stock install of php 4.2.1 with the default php.ini file. The following script demonstrates that str_replace() munches double quotes when it shouldn't. <? $source_vars[1] = '${TEXT}'; $replace_vars[1] = '<font size="1"><a href="javascript:self.close();">Close Window</a></font>'; $source_string = '<a href="${TEXT}" >'; $expandedStr = str_replace( @$source_vars, @$replace_vars, @$source_string ); print( "<h1>EXPANDED_STR is: '$expandedStr'" ); ?> You will notice that the output of this script is: <h1>EXPANDED_STR is: '<a href="<font size="1><a href="javascript:self.close();">Close Window</a></font>" >' Note the missing " at on the font tag size="1 ... If you remove the double quotes from source_string as in: $source_string = '<a href=${TEXT} >'; Then the output is correct as: <h1>EXPANDED_STR is: '<a href=<font size="1"><a href="javascript:self.close();">Close Window</a></font> >' well, aside from the fact that the href= needs the double quotes. Originally I thought this was restricted to array reference replacements but if you use the straight string form of str_replace the same behavior happen -- Edit bug report at http://bugs.php.net/?id=18440&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=18440&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=18440&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=18440&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=18440&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=18440&r=support Expected behavior: http://bugs.php.net/fix.php?id=18440&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=18440&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=18440&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=18440&r=globals

« previous php.bugs (#14659) next »