Req #48072 [Opn->Wfx]: wish: extra strtr features similar to GNU strtr
| From: | cmb@php.net | Date: | Tue, 20 Apr 2021 13:06:27 +0000 |
| Subject: | Req #48072 [Opn->Wfx]: wish: extra strtr features similar to GNU strtr | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233527@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=48072&edit=1
ID: 48072
Updated by: cmb@php.net
Reported by: php at richardneill dot org
Summary: wish: extra strtr features similar to GNU strtr
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: Strings related
Operating System: all
PHP Version: 6CVS-2009-04-24 (CVS)
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Well, deleting characters is already possible, e.g.
strtr("hello world", ['o' => '', 'd' =>
''])
Squeezing is not, but you could write your own userland
implementation. If you still feel this would be a good feature
addition, please pursue the RFC process[1].
[1] <https://wiki.php.net/rfc/howto>
Previous Comments:
------------------------------------------------------------------------
[2009-04-24 17:17:54] php at richardneill dot org
Description:
------------
Can we have the extra features added to strtr() that are in the GNU strtr? They'd be really
useful.
In particular, the ability to delete certain characters from the string [currently we must resort to
str_replace, which gets ugly], and to squeeze repeated characters to a single one [requires
preg_replace() at the moment]
This could be done by adding some predefined constants such as
STRTR_DELETE, STRTR_SQUEEZE_REPEATS
Reproduce code:
---------------
In GNU tr, we can do things like
echo "hello world" | tr -s "l"
#results in "helo world" (duplicate 'l' removed)
echo "hello world" | tr -d 'od' ('o' and 'd' removed)
#results in "hell wrl"
echo "hello world" | tr -s "wl" "zl" (translate AND squeeze)
#results in "helo zorld"
(Support for character classes might be nice too)
Thank you.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=48072&edit=1