Welcome to WebmasterWorld Guest from 54.166.117.130

Forum Moderators: coopster & jatar k

Translating characters

...which function to use in this instance?

   
10:08 pm on Jul 23, 2007 (gmt 0)

10+ Year Member



I'd like to translate these characters:

-> c
-> o

etc/etc.

Which function do I use to do this? I know that strtr is used, but I don't know how I would go about doing this.

I'm hoping someone can point me in the right direction.

-p

5:01 am on Jul 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



str_replace [php.net] maybe.
4:17 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



Where would I find the translation table?
5:24 pm on Jul 24, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



str_replace doesnt have a translation table. It is a function that lets you replace all instances of one character with another character.

Look it up in the php manual

12:54 am on Jul 27, 2007 (gmt 0)

10+ Year Member



Solved it on my own. Just in case anyone needs this at some point, I've translated the foreign characters & their HTML entities to their closest standard English character. This is not a complete array by any means, but it may help someone in the future:

$englishtranslationtable = array("Á" => "a",
"Â" => "a",
"Ä" => "a",
"À" => "a",
"Å" => "a",
"Ã" => "a",
"Æ" => "ae",
"Ç" => "c",
"É" => "e",
"Ê" => "e",
"Ë" => "e",
"È" => "e",
"Ð" => "d",
"Í" => "i",
"Î" => "i",
"Ï" => "i",
"Ì" => "i",
"Ñ" => "n",
"Ó" => "o",
"Ô" => "o",
"Ö" => "o",
"Ò" => "o",
"Ø" => "o",
"Õ" => "o",
"Þ" => "p",
"Ú" => "u",
"Û" => "u",
"Ü" => "u",
"Ù" => "u",
"Ý" => "y",
"á" => "a",
"â" => "a",
"ä" => "a",
"à" => "a",
"å" => "a",
"ã" => "a",
"æ" => "ae",
"ç" => "c",
"é" => "e",
"ê" => "e",
"ë" => "e",
"è" => "e",
"ð" => "o",
"í" => "i",
"î" => "i",
"ï" => "i",
"ì" => "i",
"ñ" => "n",
"ó" => "o",
"ô" => "o",
"ö" => "o",
"ò" => "o",
"ø" => "o",
"õ" => "o",
"ß" => "b",
"þ" => "p",
"ú" => "u",
"û" => "u",
"ü" => "u",
"ù" => "u",
"ý" => "y",
"ÿ" => "y",
"Á" => "a",
"Â" => "a",
"Ä" => "a",
"À" => "a",
"Å" => "a",
"Ã" => "a",
"Æ" => "ae",
"Ç" => "c",
"&Cedil;" => "c",
"É" => "e",
"Ê" => "e",
"Ë" => "e",
"È" => "e",
"Ð" => "d",
"Í" => "i",
"Î" => "i",
"Ï" => "i",
"Ì" => "i",
"Ñ" => "n",
"Ó" => "o",
"Ô" => "o",
"Ö" => "o",
"Ò" => "o",
"Ø" => "o",
"Õ" => "o",
"Þ" => "p",
"Ú" => "u",
"Û" => "u",
"Ü" => "u",
"Ù" => "u",
"Ý" => "y",
"á" => "a",
"â" => "a",
"ä" => "a",
"à" => "a",
"å" => "a",
"ã" => "a",
"æ" => "ae",
"¸" => "c",
"ç" => "c",
"é" => "e",
"ê" => "e",
"ë" => "e",
"è" => "e",
"ð" => "o",
"í" => "i",
"î" => "i",
"ï" => "i",
"ì" => "i",
"ñ" => "n",
"ó" => "o",
"ô" => "o",
"ö" => "o",
"ò" => "o",
"ø" => "o",
"õ" => "o",
"ß" => "b",
"þ" => "p",
"ú" => "u",
"û" => "u",
"ü" => "u",
"ù" => "u",
"ý" => "y",
"ÿ" => "y");

The point of me asking was that I did not know if there was a function that did this, and I've already searched through the manual & could not find it. But thanks anyway.

9:58 am on Jul 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless it's erroneously used for the Greek letter beta, ß is not a 'b'. It's a double s: ss. (szlig is short for s-z ligature).

As for strtr(), here's a simple example:

$simplified = strtr('', 'ae', $text);

<rant>What is an "English character"? a,b,c et cetera are latin characters whose origins can be traced to Syria and Palestine via the Etruscans, the Greeks and the Phoenicians. People on Great Britain were living in prehistory when the Romans started using most of the characters we're still using today. Only the w can claim an English origin: it was introduced by Norman scribes to represent the Anglo-Saxon sound [w].</rant>

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month