WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform
Translate certain characters

strtr

(PHP 4, PHP 5)

strtrTranslate certain characters

Description

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.

Parameters

str

The string being translated.

from

The string being translated to to .

to

The string replacing from .

replace_pairs

The replace_pairs parameter may be used as a substitute for to and from in which case it's an array in the form array('from' => 'to', ...).

Return Values

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

ChangeLog

Version Description
4.0.0 The optional to and from parameters were added.

Examples

Example #1 strtr() example

<?php
$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

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

The above example will output:

 
 hello all, I said hi 

See Also