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