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

From: Date: Fri, 19 Jul 2002 23:27:15 +0000
Subject: Bug #18440 Updated: str_replace array replace can't handle strings in quotes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-14667@lists.php.net to get a copy of this message
ID: 18440 Updated by: yml@dtlink.com Reported By: yml@dtlink.com Status: Bogus Bug Type: Strings related Operating System: Redhat 6.1 PHP Version: 4.2.1 New Comment: Definitely reproducible under PHP 4.2.1. Here's the output from phpinfo on the box where the problems is presenting: PHP Version 4.2.1 System Linux forge.yml.com 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686 unknown Build Date Jul 10 2002 19:17:13 Configure Command './configure' '--with-mysql=/usr/local/mysql' '--with-apxs=/usr/local/apache/bin/apxs' '--with-gd' Server API Apache Virtual Directory Support disabled Configuration File (php.ini) Path /usr/local/lib/php.ini Debug Build no Thread Safety disabled Zend logo This program makes use of the Zend Scripting Language Engine: Zend Engine v1.2.0, Copyright (c) 1998-2002 Zend Technologies Previous Comments: ------------------------------------------------------------------------ [2002-07-19 19:14:14] rasmus@php.net This script: $source = 'TEXT'; $replace = '<tag attribute="1"><tag attribute="blah">'; $template = '<attribute="TEXT">'; $expandedStr = str_replace( $source, $replace, $template ); print( "<h1>Result is: '$expandedStr'</h1>" ); Gives me: Result is: '<attribute="<tag attribute="1"><tag attribute="blah">">' I don't see a bug here. Try running it from the command line. Perhaps your browser is eating something. ------------------------------------------------------------------------ [2002-07-19 19:14:10] sniper@php.net I can not reproduce this with latest CVS (php 4.3.0-dev) or with PHP 4.2.1. Are you sure you're using 4.2.1? ------------------------------------------------------------------------ [2002-07-19 17:48:30] yml@dtlink.com Some more observations: $source = 'TEXT'; $replace = '<tag attribute="1"><tag attribute="blah">'; $template = '<attribute="TEXT">'; $expandedStr = str_replace( $source, $replace, $template ); print( "<h1>Result is: '$expandedStr'</h1>" ); Yields: <h1>Result is: '<attribute="<tag attribute="1><tag attribute="blah">">'</h1> as you can see, the closing " from attribute="1 is missing. HOWEVER, if we remove the angle brackets from the template (so that $template= 'attribute="TEXT"') the result is: <h1>Result is: 'attribute="<tag attribute="1"><tag attribute="blah">"'</h1> i.e. the double quote is correctly maintained. ------------------------------------------------------------------------ [2002-07-19 17:35:22] yml@dtlink.com 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 this bug report at http://bugs.php.net/?id=18440&edit=1

« previous php.bugs (#14667) next »