File:
[ELWIX - Embedded LightWeight unIX -] /
embedaddon /
php /
ext /
standard /
tests /
strings /
strtr_basic.phpt
Revision
1.1.1.1 (vendor branch):
download - view:
text,
annotated -
select for diffs -
revision graph
Tue Feb 21 23:48:04 2012 UTC (12 years, 6 months ago) by
misho
Branches:
php,
MAIN
CVS tags:
v5_4_3elwix,
v5_4_29p0,
v5_4_29,
v5_4_20p0,
v5_4_20,
v5_4_17p0,
v5_4_17,
v5_3_10,
HEAD
php
--TEST--
Test strtr() function : basic functionality
--FILE--
<?php
/* Prototype : string strtr(string $str, string $from[, string $to]);
* Description: Translates characters in str using given translation pairs
* Source code: ext/standard/string.c
*/
echo "*** Testing strtr() : basic functionality ***\n";
//definitions of required input variables
$trans1_arr = array("t" => "T", "e" => "E", "st" => "ST");
$trans2_arr = array('t' => 'T', 'e' => 'E', 'st' => 'ST');
$heredoc_str = <<<EOD
test strtr
EOD;
//translating single char
var_dump( strtr("test strtr", "t", "T") );
var_dump( strtr('test strtr', 't', 'T') );
var_dump( strtr($heredoc_str, "t", "T") );
//translating set of chars
//$from and $to are of same length
var_dump( strtr("test strtr", "test", "TEST") );
var_dump( strtr('test strtr', 'test', 'TEST') );
var_dump( strtr($heredoc_str, "test", "TEST") );
//$from and $to are of different lengths, extra chars in the longer one are ignored
var_dump( strtr("test strtr", "test", "TESTz") );
var_dump( strtr('test strtr', 'testz', 'TEST') );
var_dump( strtr($heredoc_str, "test", "TESTz") );
//by using replace_pairs array
var_dump( strtr("test strtr", $trans1_arr) );
var_dump( strtr('test strtr', $trans2_arr) );
var_dump( strtr($heredoc_str, $trans1_arr) );
echo "*** Done ***";
?>
--EXPECTF--
*** Testing strtr() : basic functionality ***
string(10) "TesT sTrTr"
string(10) "TesT sTrTr"
string(10) "TesT sTrTr"
string(10) "TEST STrTr"
string(10) "TEST STrTr"
string(10) "TEST STrTr"
string(10) "TEST STrTr"
string(10) "TEST STrTr"
string(10) "TEST STrTr"
string(10) "TEST STrTr"
string(10) "TEST STrTr"
string(10) "TEST STrTr"
*** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>