From:             a at b dot c dot de
Operating system: Any
PHP version:      5.4.3
Package:          Strings related
Bug Type:         Feature/Change Request
Bug description:Mixed first argument for strtr

Description:
------------
While preg_replace and str_replace can both apply changes to arrays of
strings, strtr can only be passed one string at a time for translation; it
can only be called as strtr(string, string, string) or strtr(string,
array).

This suggestion/request is for strtr to be support being called as, for
example, strtr(array, string1$, string2$) (which would be effectively
equivalent to array_map(function($w)use($string1, $string2) { return
strtr($w, $string1, $string2); }, $array)).

This would bring it into closer line with the other
"string-search-and-replace" functions.

Test script:
---------------
$words = ['this', 'is', 'a', 'bunch', 'of', 'words', 'with', 'no',
'rhythm'];

$translated = strtr($words, 'aeiou', 'AEIOU');

print_r($translated);

Expected result:
----------------
Array
(
    [0] => thIs
    [1] => Is
    [2] => A
    [3] => bUnch
    [4] => Of
    [5] => wOrds
    [6] => wIth
    [7] => nO
    [8] => rhythm
)

Actual result:
--------------
A warning about a parameter 1 being an array instead of the expected
string.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=62291&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62291&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62291&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62291&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62291&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62291&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62291&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62291&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62291&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62291&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62291&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62291&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62291&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62291&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62291&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62291&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62291&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62291&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62291&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62291&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62291&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62291&r=mysqlcfg

Reply via email to