1--TEST--
2Test strtr() function : basic functionality
3--FILE--
4<?php
5/* Prototype  : string strtr(string $str, string $from[, string $to]);
6 * Description: Translates characters in str using given translation pairs
7 * Source code: ext/standard/string.c
8*/
9
10echo "*** Testing strtr() : basic functionality ***\n";
11//definitions of required input variables
12$trans1_arr = array("t" => "T", "e" => "E", "st" => "ST");
13$trans2_arr = array('t' => 'T', 'e' => 'E', 'st' => 'ST');
14$heredoc_str = <<<EOD
15test strtr
16EOD;
17
18//translating single char
19var_dump( strtr("test strtr", "t", "T") );
20var_dump( strtr('test strtr', 't', 'T') );
21var_dump( strtr($heredoc_str, "t", "T") );
22
23//translating set of chars
24//$from and $to are of same length
25var_dump( strtr("test strtr", "test", "TEST") );
26var_dump( strtr('test strtr', 'test', 'TEST') );
27var_dump( strtr($heredoc_str, "test", "TEST") );
28
29//$from and $to are of different lengths, extra chars in the longer one are ignored
30var_dump( strtr("test strtr", "test", "TESTz") );
31var_dump( strtr('test strtr', 'testz', 'TEST') );
32var_dump( strtr($heredoc_str, "test", "TESTz") );
33
34//by using replace_pairs array
35var_dump( strtr("test strtr", $trans1_arr) );
36var_dump( strtr('test strtr', $trans2_arr) );
37var_dump( strtr($heredoc_str, $trans1_arr) );
38echo "*** Done ***";
39?>
40--EXPECTF--
41*** Testing strtr() : basic functionality ***
42string(10) "TesT sTrTr"
43string(10) "TesT sTrTr"
44string(10) "TesT sTrTr"
45string(10) "TEST STrTr"
46string(10) "TEST STrTr"
47string(10) "TEST STrTr"
48string(10) "TEST STrTr"
49string(10) "TEST STrTr"
50string(10) "TEST STrTr"
51string(10) "TEST STrTr"
52string(10) "TEST STrTr"
53string(10) "TEST STrTr"
54*** Done ***
55