1--TEST-- 2Test strtr() function : usage variations - string containing special chars for 'str' argument 3--FILE-- 4<?php 5/* Testing strtr() function by passing the 6 * string containing various special characters for 'str' argument and 7 * corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments 8*/ 9 10echo "*** Testing strtr() : string containing special chars for 'str' arg ***\n"; 11 12/* definitions of required input variables */ 13$count = 1; 14 15$heredoc_str = <<<EOD 16% 17#$*& 18text & @() 19EOD; 20 21//array of string inputs for $str 22$str_arr = array( 23 //double quoted strings 24 "%", 25 "#$*", 26 "text & @()", 27 28 //single quoted strings 29 '%', 30 '#$*', 31 'text & @()', 32 33 //heredoc string 34 $heredoc_str 35); 36 37$from = "%#$*&@()"; 38$to = "specials"; 39$replace_pairs = array("$" => "%", "%" => "$", "#*&@()" => "()@&*#"); 40 41/* loop through to test strtr() with each element of $str_arr */ 42for($index = 0; $index < count($str_arr); $index++) { 43 echo "-- Iteration $count --\n"; 44 45 $str = $str_arr[$index]; //getting the array element in 'str' variable 46 47 //strtr() call in three args syntax form 48 var_dump( strtr($str, $from, $to) ); 49 50 //strtr() call in two args syntax form 51 var_dump( strtr($str, $replace_pairs) ); 52 53 $count++; 54} 55echo "*** Done ***"; 56?> 57--EXPECT-- 58*** Testing strtr() : string containing special chars for 'str' arg *** 59-- Iteration 1 -- 60string(1) "s" 61string(1) "$" 62-- Iteration 2 -- 63string(3) "pec" 64string(3) "#%*" 65-- Iteration 3 -- 66string(10) "text i als" 67string(10) "text & @()" 68-- Iteration 4 -- 69string(1) "s" 70string(1) "$" 71-- Iteration 5 -- 72string(3) "pec" 73string(3) "#%*" 74-- Iteration 6 -- 75string(10) "text i als" 76string(10) "text & @()" 77-- Iteration 7 -- 78string(17) "s 79peci 80text i als" 81string(17) "$ 82#%*& 83text & @()" 84*** Done *** 85