Bug #69022 [Opn->Nab]: strtr fails to consistently translate to an empty string
| From: | requinix@php.net | Date: | Tue, 10 Feb 2015 04:17:57 +0000 |
| Subject: | Bug #69022 [Opn->Nab]: strtr fails to consistently translate to an empty string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-190563@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69022&edit=1
ID: 69022
Updated by: requinix@php.net
Reported by: slevy1 at pipeline dot com
Summary: strtr fails to consistently translate to an empty
string
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.6.5
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
That's right.
http://php.net/manual/en/function.strtr.php
>If from and to have different lengths, the extra characters in the longer of the
>two are ignored. The length of str will be the same as the return value's.
Previous Comments:
------------------------------------------------------------------------
[2015-02-10 03:57:21] slevy1 at pipeline dot com
Description:
------------
If I provide strtr a from value like a comma, and a to value like an empty string, since the from
value is longer than the to value, the translation fails to occur.
However, if I provide the from and to values in an associative array, then the comma in the from
value is replaced by an an empty string in the to value.
Test script:
---------------
<?php
$nums = "1,2,3,\n,4,5,6,\n,7,8,9";
echo strtr($nums,array("," => ""));
echo "\n\n";
echo strtr($nums,",","");
Expected result:
----------------
123
456
789
123
456
789
Actual result:
--------------
123
456
789
1,2,3,
,4,5,6,
,7,8,9
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69022&edit=1