homepage Welcome to WebmasterWorld Guest from 54.161.191.154
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Translating characters
...which function to use in this instance?
panic

10+ Year Member



 
Msg#: 3402492 posted 10:08 pm on Jul 23, 2007 (gmt 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

 

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3402492 posted 5:01 am on Jul 24, 2007 (gmt 0)

str_replace [php.net] maybe.

panic

10+ Year Member



 
Msg#: 3402492 posted 4:17 pm on Jul 24, 2007 (gmt 0)

Where would I find the translation table?

PHP_Chimp

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3402492 posted 5:24 pm on Jul 24, 2007 (gmt 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

panic

10+ Year Member



 
Msg#: 3402492 posted 12:54 am on Jul 27, 2007 (gmt 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.

RonPK

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3402492 posted 9:58 am on Jul 27, 2007 (gmt 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>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved