 The strtr PHP function can be easily used to replace all the occurrences of letters in a string for other letters, and it can also receive a list (array) of replacement words; doing all the necessary changes in one clean sweep.
When all you need to replace is letters, the strtr function receives 3 arguments: The original string, the letters to find and the replacements:
$raw_string="Text with áccénts";
echo strtr($raw_string, "áé", "ae");
But when replacing words, you can quickly setup and array and use only two arguments in the function call:
$swap_list = array("%ftcolor%" => "dark gray", "%bgcolor%" => "white");
echo strtr("The font color is %ftcolor%, and the background is %bgcolor%", $swap_list);
Here is a useful example; code for replacing tabs and line jumps with HTML equivalents:
$swap_list = array("\t" => " ", "\n" => "<br>");
echo strtr("\tSample input\n like you could expect from a visitor", $swap_list);
Author : Esopo, Read 4415 times, Comments: 2| Rating : |           | | Sunday, 24. July 2005 |
Add new comment/Comments
Your rating : Poor     Excellent |
  Did you know? There is a wallpaper gallery? Yeap, it took me a while to code it and put it together for your entertainment. Check it out and, if you like it, drop me a line.
Visit gallery
  Featured * Simple, powerful and reliable. There is not much more you can ask of your FTP. I used to switch FTPs a lot until I found this one; now I never have FTP problems. I do like FTP Voyager’s interface better, but given Filezilla's free nature… what can I say? I got emotionally attached. An outstanding compilation of some of the best Flash sites out there. As usual with Flash sites, most are useless elaborated animations, but nevertheless worthwhile having a look. http://www.greg.ch/flash/ |