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

1.1       misho       1: --TEST--
                      2: Test strtr() function : usage variations - string containing special chars 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 special characters for 'str' argument and
                     13:  *   corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments
                     14: */
                     15: 
                     16: echo "*** Testing strtr() : string containing special chars for 'str' arg ***\n";
                     17: 
                     18: /* definitions of required input variables */
                     19: $count = 1;
                     20: 
                     21: $heredoc_str = <<<EOD
                     22: %
                     23: #$*&
                     24: text & @()
                     25: EOD;
                     26: 
                     27: //array of string inputs for $str
                     28: $str_arr = array(
                     29:   //double quoted strings
                     30:   "%",
                     31:   "#$*",
                     32:   "text & @()",
                     33: 
                     34:   //single quoted strings
                     35:   '%',
                     36:   '#$*',
                     37:   'text & @()',
                     38: 
                     39:   //heredoc string
                     40:   $heredoc_str
                     41: );
                     42: 
                     43: $from = "%#$*&@()";
                     44: $to = "specials";
                     45: $replace_pairs = array("$" => "%", "%" => "$", "#*&@()" => "()@&*#");
                     46: 
                     47: /* loop through to test strtr() with each element of $str_arr */
                     48: for($index = 0; $index < count($str_arr); $index++) {
                     49:   echo "-- Iteration $count --\n";
                     50: 
                     51:   $str = $str_arr[$index];  //getting the array element in 'str' variable
                     52: 
                     53:   //strtr() call in three args syntax form
                     54:   var_dump( strtr($str, $from, $to) );
                     55: 
                     56:   //strtr() call in two args syntax form
                     57:   var_dump( strtr($str, $replace_pairs) );
                     58: 
                     59:   $count++;
                     60: }
                     61: echo "*** Done ***";
                     62: ?>
                     63: --EXPECTF--
                     64: *** Testing strtr() : string containing special chars for 'str' arg ***
                     65: -- Iteration 1 --
                     66: string(1) "s"
                     67: string(1) "$"
                     68: -- Iteration 2 --
                     69: string(3) "pec"
                     70: string(3) "#%*"
                     71: -- Iteration 3 --
                     72: string(10) "text i als"
                     73: string(10) "text & @()"
                     74: -- Iteration 4 --
                     75: string(1) "s"
                     76: string(1) "$"
                     77: -- Iteration 5 --
                     78: string(3) "pec"
                     79: string(3) "#%*"
                     80: -- Iteration 6 --
                     81: string(10) "text i als"
                     82: string(10) "text & @()"
                     83: -- Iteration 7 --
                     84: string(17) "s
                     85: peci
                     86: text i als"
                     87: string(17) "$
                     88: #%*&
                     89: text & @()"
                     90: *** Done ***

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