Page 1 of 1

Replacing accented chars using strtr, in UTF8

Posted: Tue Apr 25, 2006 12:28 pm
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!!

Posted: Tue Apr 25, 2006 12:30 pm
by feyd
str_replace() should work just fine...

Posted: Tue Apr 25, 2006 1:33 pm
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

Posted: Tue Apr 25, 2006 2:00 pm
by feyd
You can give str_replace() an array for both the search and replacement arguments. Yeah, it'll work.

Posted: Tue Apr 25, 2006 2:08 pm
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!! :)