Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #35232 : error in str_replace/str_ireplace with array type arguments
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 9th June 10:32
php-bugs@lists.php.net (o_eclipse at mail dot
External User
 
Posts: 1
Default #35232 : error in str_replace/str_ireplace with array type arguments



From: o_eclipse at mail dot ru
Operating system: Windows
PHP version: 5.0.5
PHP Bug Type: Unknown/Other Function
Bug description: error in str_replace/str_ireplace with array type arguments

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 bug report at http://bugs.php.net/?id=35232&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35232&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35232&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35232&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=35232&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35232&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35232&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35232&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35232&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35232&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35232&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=35232&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=35232&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35232&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35232&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35232&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35232&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35232&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35232&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35232&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35232&r=mysqlcfg
  Reply With Quote


  sponsored links


2 9th June 10:32
tony2001
External User
 
Posts: 1
Default #35232 : error in str_replace/str_ireplace with array type arguments



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
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666