|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-11-16 00:15 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Fri Apr 03 23:00:01 2026 UTC |
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*