php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41785 function strtr
Submitted: 2007-06-23 05:49 UTC Modified: 2007-06-23 08:34 UTC
From: saint at mail dot ntch dot edu dot tw Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.3 OS: CentOS5
Private report: No CVE-ID: None
 [2007-06-23 05:49 UTC] saint at mail dot ntch dot edu dot tw
Description:
------------
i hope string 0554 to 0673
print strtr( '8081;0647;0554' , '0554', '0673')
print string 8081;0637;0773
i hope string is 8081;0647;0673
print str_replace( '8081;0647;0554', '0554', '0673' );
print string 8081;0647;0673
string is right



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-23 08:34 UTC] rasmus@php.net
strtr works on a per-character basis.  Not on entire strings like that.  The output is correct.  The documentation is very clear on this:

 "This function returns a copy of str, translating all occurrences of each character in from to the corresponding character in to."

So in your case you are mapping 0554 to 0673 which doesn't actually make any sense.  You are saying that 0 becomes 0, 5 becomes 6, 5 becomes 7 and 4 becomes 3.  Since you have two mappings for 5, PHP takes the second one, so your translation table is 5->7 and 4->3.  Therefore 0647;0554 becomes 0636;0773 
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 12:00:02 2026 UTC