PHP Wysardry
PHP Manual

PHP documentation.



Home / PHP / Manual / ...



PHP Manual
Prev Next

strtr

(PHP 3 <= 3.0.18, PHP 4 >= 4.0.0)

strtr -- Translate certain characters

Description

string strtr (string str, string from, string to)

This function returns a copy of str, translating all occurrences of each character in from to the corresponding character in to and returning the result.

If from and to are different lengths, the extra characters in the longer of the two are ignored.

Example 1. strtr() example

$addr = strtr($addr, "äåö", "aao");

strtr() can be called with only two arguments. If called with two arguments it behaves in a new way: from then has to be an array that contains string -> string pairs that will be replaced in the source string. strtr() will always look for the longest possible match first and will *NOT* try to replace stuff that it has already worked on.

Examples:

$trans = array("hello" => "hi", "hi" => "hello");
echo strtr("hi all, I said hello", $trans) . "\n";
This will show: "hello all, I said hi",

Note: This optional to and from parameters were added in PHP 4.0.0

See also ereg_replace().


Prev Manual Home Next
str_replace Up substr
Site Menu

Amazon.ca
Amazon.com
Amazon.co.uk



Most recently updated on 11 May, 2003

Home / PHP / Manual / ...



Please feel free to contact us with any comments or suggestions
PHP Manual
PHP Wysardry

This site is hosted by Spaceports