Bug #72797 [NEW]: Bug in str_replace with arrays if the second one starts with a space
| From: | info at maduranma dot com | Date: | Tue, 09 Aug 2016 18:31:54 +0000 |
| Subject: | Bug #72797 [NEW]: Bug in str_replace with arrays if the second one starts with a space | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-203122@lists.php.net to get a copy of this message | ||
From: info at maduranma dot com
Operating system: Windows
PHP version: 7.0.9
Package: Arrays related
Bug Type: Bug
Bug description:Bug in str_replace with arrays if the second one starts with a space
Description:
------------
In the code below, if you change the first "' '" of the second array in
the str_replace function with some kind of value it doesn't happen, but
if you do not, it takes it to the last value of the array, that's "'0'"
and you can change it to "'ssdsad'" (for example) and you'll see that it
takes the last value.
Test script:
---------------
$msg = 'AABB';
$msg = str_replace(array('A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'Ã',
'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V',
'W', 'X', 'Y', 'Z', '1', '2',
'3', '4', '5', '6', '7', '8',
'9', '0', '
'), array(' ', 'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J',
'K',
'L', 'M', 'N', 'Ã', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X',
'Y', 'Z', '1', '2', '3', '4',
'5', '6', '7', '8', '9', '0'), $msg); //
N-1
echo $msg;
Expected result:
----------------
AA
Actual result:
--------------
00AA
--
Edit bug report at https://bugs.php.net/bug.php?id=72797&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72797&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72797&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72797&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72797&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72797&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72797&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72797&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72797&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72797&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72797&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72797&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72797&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72797&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72797&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72797&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72797&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72797&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72797&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72797&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72797&r=mysqlcfg