strtr_variation2.phpt [plain text]
--TEST--
Test strtr() function : usage variations - string containing special chars for 'str' argument
--FILE--
<?php
echo "*** Testing strtr() : string containing special chars for 'str' arg ***\n";
$count = 1;
$heredoc_str = <<<EOD
%
#$*&
text & @()
EOD;
$str_arr = array(
"%",
"#$*",
"text & @()",
'%',
'#$*',
'text & @()',
$heredoc_str
);
$from = "%#$*&@()";
$to = "specials";
$replace_pairs = array("$" => "%", "%" => "$", "#*&@()" => "()@&*#");
for($index = 0; $index < count($str_arr); $index++) {
echo "-- Iteration $count --\n";
$str = $str_arr[$index];
var_dump( strtr($str, $from, $to) );
var_dump( strtr($str, $replace_pairs) );
$count++;
}
echo "*** Done ***";
?>
--EXPECTF--
*** Testing strtr() : string containing special chars for 'str' arg ***
-- Iteration 1 --
string(1) "s"
string(1) "$"
-- Iteration 2 --
string(3) "pec"
string(3) "#%*"
-- Iteration 3 --
string(10) "text i als"
string(10) "text & @()"
-- Iteration 4 --
string(1) "s"
string(1) "$"
-- Iteration 5 --
string(3) "pec"
string(3) "#%*"
-- Iteration 6 --
string(10) "text i als"
string(10) "text & @()"
-- Iteration 7 --
string(17) "s
peci
text i als"
string(17) "$
#%*&
text & @()"
*** Done ***