strtr_variation1.phpt [plain text]
--TEST--
Test strtr() function : usage variations - regular & numeric strings for 'str' argument
--FILE--
<?php
echo "*** Testing strtr() : numeric & regular double quoted strings ***\n";
$count = 1;
$heredoc_str = <<<EOD
123
abc
1a2b3c
EOD;
$str_arr = array(
"123",
"abc",
"1a2b3c",
'123',
'abc',
'1a2b3c',
$heredoc_str
);
$from = "123abc";
$to = "abc123";
$replace_pairs = array("1" => "a", "a" => 1, "2b3c" => "b2c3", "b2c3" => "3c2b");
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() : numeric & regular double quoted strings ***
-- Iteration 1 --
string(3) "abc"
string(3) "a23"
-- Iteration 2 --
string(3) "123"
string(3) "1bc"
-- Iteration 3 --
string(6) "a1b2c3"
string(6) "a1b2c3"
-- Iteration 4 --
string(3) "abc"
string(3) "a23"
-- Iteration 5 --
string(3) "123"
string(3) "1bc"
-- Iteration 6 --
string(6) "a1b2c3"
string(6) "a1b2c3"
-- Iteration 7 --
string(14) "abc
123
a1b2c3"
string(14) "a23
1bc
a1b2c3"
*** Done ***