Welcome to WebmasterWorld Guest from 54.198.118.102

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Translating characters

...which function to use in this instance?

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

Preferred Member

10+ Year Member

joined:June 16, 2003
posts:633
votes: 0


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 July 24, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
posts:1867
votes: 0


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

Preferred Member

10+ Year Member

joined:June 16, 2003
posts:633
votes: 0


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

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:July 12, 2007
posts:766
votes: 0


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 July 27, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:June 16, 2003
posts:633
votes: 0


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 July 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 22, 2002
posts:1749
votes: 0


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>