PHP » GoLang |
login |
register |
about
|
strtr(PHP 4, PHP 5, PHP 7) strtr — Translate characters or replace substrings Description
string strtr
( string
$str
, string $from
, string $to
)
string strtr
( string
$str
, array $replace_pairs
)
If given three arguments, this function returns a copy of
If If given two arguments, the second should be an array in the form array('from' => 'to', ...). The return value is a string where all the occurrences of the array keys have been replaced by the corresponding values. The longest keys will be tried first. Once a substring has been replaced, its new value will not be searched again.
In this case, the keys and the values may have any length, provided that
there is no empty key; additionally, the length of the return value may
differ from that of Parameters
Return ValuesReturns the translated string.
If Examples
Example #1 strtr() example
<?php The next example shows the behavior of strtr() when called with only two arguments. Note the preference of the replacements ("h" is not picked because there are longer matches) and how replaced text was not searched again. Example #2 strtr() example with two arguments
<?php The above example will output: hello all, I said hi The two modes of behavior are substantially different. With three arguments, strtr() will replace bytes; with two, it may replace longer substrings. Example #3 strtr() behavior comparison
<?php The above example will output: 1001 ba01 See Also
|
more
Recently updated
more
Most requested
more
Last requests
|