Annotation of embedaddon/php/ext/standard/tests/strings/strtr_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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:
10: echo "*** 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
15: test strtr
16: EOD;
17:
18: //translating single char
19: var_dump( strtr("test strtr", "t", "T") );
20: var_dump( strtr('test strtr', 't', 'T') );
21: var_dump( strtr($heredoc_str, "t", "T") );
22:
23: //translating set of chars
24: //$from and $to are of same length
25: var_dump( strtr("test strtr", "test", "TEST") );
26: var_dump( strtr('test strtr', 'test', 'TEST') );
27: var_dump( strtr($heredoc_str, "test", "TEST") );
28:
29: //$from and $to are of different lengths, extra chars in the longer one are ignored
30: var_dump( strtr("test strtr", "test", "TESTz") );
31: var_dump( strtr('test strtr', 'testz', 'TEST') );
32: var_dump( strtr($heredoc_str, "test", "TESTz") );
33:
34: //by using replace_pairs array
35: var_dump( strtr("test strtr", $trans1_arr) );
36: var_dump( strtr('test strtr', $trans2_arr) );
37: var_dump( strtr($heredoc_str, $trans1_arr) );
38: echo "*** Done ***";
39: ?>
40: --EXPECTF--
41: *** Testing strtr() : basic functionality ***
42: string(10) "TesT sTrTr"
43: string(10) "TesT sTrTr"
44: string(10) "TesT sTrTr"
45: string(10) "TEST STrTr"
46: string(10) "TEST STrTr"
47: string(10) "TEST STrTr"
48: string(10) "TEST STrTr"
49: string(10) "TEST STrTr"
50: string(10) "TEST STrTr"
51: string(10) "TEST STrTr"
52: string(10) "TEST STrTr"
53: string(10) "TEST STrTr"
54: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>