Annotation of embedaddon/php/ext/standard/tests/strings/strtr_variation3.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test strtr() function : usage variations - string containing escape sequences 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:  *   string containing various escape sequences for 'str' argument and
                     13:  *   corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments
                     14: */
                     15: 
                     16: echo "*** Testing strtr() : string containing escape sequences for 'str' arg ***\n";
                     17: /* definitions of required input variables */
                     18: $count = 1;
                     19: 
                     20: $heredoc_str = <<<EOD
                     21: \tes\t\\stt\r
                     22: \\test\\\strtr
                     23: \ntest\r\nstrtr
                     24: \$variable
                     25: \"quotes
                     26: EOD;
                     27: 
                     28: //array of string inputs for $str
                     29: $str_arr = array(
                     30:   //double quoted strings
                     31:   "\tes\t\\stt\r",
                     32:   "\\test\\\strtr",
                     33:   "\ntest\r\nstrtr",
                     34:   "\$variable",
                     35:   "\"quotes",
                     36: 
                     37:   //single quoted strings
                     38:   '\tes\t\\stt\r',
                     39:   '\\test\\\strtr',
                     40:   '\ntest\r\nstrtr',
                     41:   '\$variable',
                     42:   '\"quotes',
                     43: 
                     44:   //heredoc string
                     45:   $heredoc_str
                     46: );
                     47: 
                     48: $from = "\n\r\t\\";
                     49: $to = "TEST";
                     50: $replace_pairs = array("\n" => "t", "\r\n" => "T", "\n\r\t\\" => "TEST");
                     51: 
                     52: /* loop through to test strtr() with each element of $str_arr */
                     53: for($index = 0; $index < count($str_arr); $index++) {
                     54:   echo "-- Iteration $count --\n";
                     55: 
                     56:   $str = $str_arr[$index];  //getting the array element in 'str' variable
                     57: 
                     58:   //strtr() call in three args syntax form
                     59:   var_dump( strtr($str, $from, $to) );
                     60: 
                     61:   //strtr() call in two args syntax form
                     62:   var_dump( strtr($str, $replace_pairs) );
                     63: 
                     64:   $count++;
                     65: }
                     66: echo "*** Done ***";
                     67: ?>
                     68: --EXPECTF--
                     69: *** Testing strtr() : string containing escape sequences for 'str' arg ***
                     70: -- Iteration 1 --
                     71: string(9) "SesSTsttE"
                     72: string(9) "    es      \stt
"
                     73: -- Iteration 2 --
                     74: string(12) "TtestTTstrtr"
                     75: string(12) "\test\\strtr"
                     76: -- Iteration 3 --
                     77: string(12) "TtestETstrtr"
                     78: string(11) "ttestTstrtr"
                     79: -- Iteration 4 --
                     80: string(9) "$variable"
                     81: string(9) "$variable"
                     82: -- Iteration 5 --
                     83: string(7) ""quotes"
                     84: string(7) ""quotes"
                     85: -- Iteration 6 --
                     86: string(12) "TtesTtTsttTr"
                     87: string(12) "\tes\t\stt\r"
                     88: -- Iteration 7 --
                     89: string(12) "TtestTTstrtr"
                     90: string(12) "\test\\strtr"
                     91: -- Iteration 8 --
                     92: string(15) "TntestTrTnstrtr"
                     93: string(15) "\ntest\r\nstrtr"
                     94: -- Iteration 9 --
                     95: string(10) "T$variable"
                     96: string(10) "\$variable"
                     97: -- Iteration 10 --
                     98: string(8) "T"quotes"
                     99: string(8) "\"quotes"
                    100: -- Iteration 11 --
                    101: string(54) "SesSTsttETTtestTTstrtrTTtestETstrtrT$variableTT"quotes"
                    102: string(52) "   es      \sttT\test\\strtrtttestTstrtrt$variablet\"quotes"
                    103: *** Done ***

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>