Replacing accented chars using strtr, in UTF8

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cripes
Forum Newbie
Posts: 8
Joined: Sat Mar 19, 2005 5:16 am

Replacing accented chars using strtr, in UTF8

Post by cripes »

I am needing to "clean" strings of characters that include accents.

That is, I need to turn "élève" into "eleve".

In the past, I have used a function like this:

Code: Select all

$clean_string = strtr($accented_string, "éè", "ee");
But the site I'm working on now is in UTF8. The above function is not working at all - it is replacing each accented letter by two characters, where one of them is seemingly random.

Can anyone offer any help here??

thanks!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

str_replace() should work just fine...
cripes
Forum Newbie
Posts: 8
Joined: Sat Mar 19, 2005 5:16 am

Post by cripes »

feyd wrote:str_replace() should work just fine...
Well, not really: I have dozens of characters to replace, that's why I was using
strtr($accented_string, "éèêëàçôûî", "eeeeacoui") etc
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can give str_replace() an array for both the search and replacement arguments. Yeah, it'll work.
cripes
Forum Newbie
Posts: 8
Joined: Sat Mar 19, 2005 5:16 am

Post by cripes »

feyd wrote:You can give str_replace() an array for both the search and replacement arguments. Yeah, it'll work.
oh. ooops. Sorry, I hadn't realized that at all - thanks feyd!! :)
Post Reply