Most Referenced Functions
  » google_pagerank()
  » preg_replace()
  » imagecreatefrompng()
  » site_pageranks()
  » imagepng()
  » imagestring()
  » imagedestroy()
  » htmlentities()
  » imagecolorallocate()
  » fopen()
  » preg_match()
  » header()
  » getimagesize()
  » session_start()
  » ob_start()
  » preg_match_all()
  » strstr()
  » flush()
  » ob_flush()
  » strpos()
  » str_replace()
  » array2vars()
  » htmlspecialchars()
  » nl2br()
  » setcookie()
  » urlencode()
  » preg_split()
  » ereg()
  » ereg_replace()
  » var_dump()

Become a sponsor for $15/month. Link is sitewide - PR5 homepage, 20+ PR4 pages, 90+ PR3 pages. Email dave[AT]icemelon[D0T]c0m.

PHP Functions

Function: strtr

(PHP 3, PHP 4, PHP 5)

strtr -- Translate 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.

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);
?>

This will show:

hello all, I said hi

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

Related Function(s)

  • ereg_replace()
  • Icemelon -- PHP, CSS, Javascript Tutorials, & More!
      © 2005-2010 Icemelon.com   Email: dave[AT]icemelon[D0T]c0m