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

1.1       misho       1: --TEST--
                      2: Test 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: 
                     16: echo "*** Testing strtr() : numeric & regular double quoted strings ***\n";
                     17: /* definitions of required input variables */
                     18: $count = 1;
                     19: $heredoc_str = <<<EOD
                     20: 123
                     21: abc
                     22: 1a2b3c
                     23: EOD;
                     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 */
                     44: for($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: }
                     57: echo "*** Done ***";
                     58: ?>
                     59: --EXPECTF--
                     60: *** Testing strtr() : numeric & regular double quoted strings ***
                     61: -- Iteration 1 --
                     62: string(3) "abc"
                     63: string(3) "a23"
                     64: -- Iteration 2 --
                     65: string(3) "123"
                     66: string(3) "1bc"
                     67: -- Iteration 3 --
                     68: string(6) "a1b2c3"
                     69: string(6) "a1b2c3"
                     70: -- Iteration 4 --
                     71: string(3) "abc"
                     72: string(3) "a23"
                     73: -- Iteration 5 --
                     74: string(3) "123"
                     75: string(3) "1bc"
                     76: -- Iteration 6 --
                     77: string(6) "a1b2c3"
                     78: string(6) "a1b2c3"
                     79: -- Iteration 7 --
                     80: string(14) "abc
                     81: 123
                     82: a1b2c3"
                     83: string(14) "a23
                     84: 1bc
                     85: a1b2c3"
                     86: *** Done ***

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