#35232 [Opn->Bgs]: error in str_replace/str_ireplace with array type arguments
| From: | tony2001@php.net | Date: | Tue, 15 Nov 2005 23:15:29 +0000 |
| Subject: | #35232 [Opn->Bgs]: error in str_replace/str_ireplace with array type arguments | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-88240@lists.php.net to get a copy of this message | ||
ID: 35232
Updated by: tony2001@php.net
Reported By: o_eclipse at mail dot ru
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Windows
PHP Version: 5.0.5
New Comment:
You're replacing 1 with 8 and *after that* 8 with 1.
Same goes with 6,7 & 9.
Obviously you're wrong with your expectations.
No bug here.
Previous Comments:
------------------------------------------------------------------------
[2005-11-15 23:55:24] o_eclipse at mail dot ru
Description:
------------
Functions str_replace / str_ireplace give incorrect result when
'replace' argument is array filled with numbers.
Reproduce code:
---------------
<?php
$subject = "*0-1-2-3-4-5-6-7-8-9*";
$search = array ( "-", "0", "1", "2", "3",
"4", "5", "6", "7", "8",
"9" );
$replace = array ( "+", "a", "b", "c", "d",
"e", "f", "g", "h", "i",
"j" );
$result = str_replace($search, $replace, $subject);
echo "$result\n"; // result is *a+b+c+d+e+f+g+h+i+j*
$replace = array ( "+", "9", "8", "7", "6",
"5", "4", "3", "2", "1",
"0" );
$result = str_replace($search, $replace, $subject);
echo "$result\n"; // result is *0+1+2+3+4+4+3+2+1+0*
// must be *0+1+2+3+4+5+6+7+8+9*
?>
Expected result:
----------------
the program output should be like this:
*a+b+c+d+e+f+g+h+i+j*
*0+1+2+3+4+5+6+7+8+9*
Actual result:
--------------
that`s what we get:
*a+b+c+d+e+f+g+h+i+j*
*0+1+2+3+4+4+3+2+1+0*
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35232&edit=1