How to str function works?

 Published April 23,2010 in PHP

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


string strtr ( string str, array replace_pairs )

 

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

 

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() may 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.

Example 2. strtr() example with two arguments

$trans = array("hello" => "hi", "hi" => "hello"); echo strtr("hi all, I said hello", $trans);

 

Output:

hello all, I said hi

 

 

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



Like our site? Be a member of Coolajax fan page to get daily posts updates!

recommended-tutorial You May Like This Posts!

» How to strspn function works?

» How to str_split function work?

» How to str function works?

» How to strrpos function work?

» while loop in php

  tuts_view Total Read: 418
blog comments powered by Disqus

Topics

Coolajax Fans

coolajax fan page on Facebook