php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48072 wish: extra strtr features similar to GNU strtr
Submitted: 2009-04-24 17:17 UTC Modified: 2021-04-20 13:06 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: php at richardneill dot org Assigned: cmb (profile)
Status: Wont fix Package: Strings related
PHP Version: 6CVS-2009-04-24 (CVS) OS: all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at richardneill dot org
New email:
PHP Version: OS:

 

 [2009-04-24 17:17 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-20 13:06 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: Strings related -Assigned To: +Assigned To: cmb
 [2021-04-20 13:06 UTC] cmb@php.net
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>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC