Return to strtr_variation4.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test strtr() function : usage variations - empty string & null for 'str' argument 3: --FILE-- 4: <?php 5: /* Prototype : string strtr(string $str, string $from[, string $to]); 6: string strtr(string $str, array $replace_pairs); 7: * Description: Translates characters in str using given translation tables 8: * Source code: ext/standard/string.c 9: */ 10: 11: /* Testing strtr() function by passing the 12: * empty string & null for 'str' argument and 13: * corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments 14: */ 15: 16: echo "*** Testing strtr() : empty string & null for 'str' arg ***\n"; 17: /* definitions of required input variables */ 18: $count = 1; 19: 20: $heredoc_str = <<<EOD 21: 22: EOD; 23: 24: //array of string inputs for $str 25: $str_arr = array( 26: "", 27: '', 28: NULL, 29: null, 30: FALSE, 31: false, 32: $heredoc_str 33: ); 34: 35: $from = ""; 36: $to = "TEST"; 37: $replace_pairs = array("" => "t", '' => "TEST"); 38: 39: 40: /* loop through to test strtr() with each element of $str_arr */ 41: for($index = 0; $index < count($str_arr); $index++) { 42: echo "-- Iteration $count --\n"; 43: 44: $str = $str_arr[$index]; //getting the array element in 'str' variable 45: 46: //strtr() call in three args syntax form 47: var_dump( strtr($str, $from, $to) ); 48: 49: //strtr() call in two args syntax form 50: var_dump( strtr($str, $replace_pairs) ); 51: 52: $count++; 53: } 54: echo "*** Done ***"; 55: ?> 56: --EXPECTF-- 57: *** Testing strtr() : empty string & null for 'str' arg *** 58: -- Iteration 1 -- 59: string(0) "" 60: string(0) "" 61: -- Iteration 2 -- 62: string(0) "" 63: string(0) "" 64: -- Iteration 3 -- 65: string(0) "" 66: string(0) "" 67: -- Iteration 4 -- 68: string(0) "" 69: string(0) "" 70: -- Iteration 5 -- 71: string(0) "" 72: string(0) "" 73: -- Iteration 6 -- 74: string(0) "" 75: string(0) "" 76: -- Iteration 7 -- 77: string(0) "" 78: string(0) "" 79: *** Done ***