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