5

Is there a function that coverts special characters to their english equivalents. For Eg. Convert é to e. Etc...

castor
  • 51
  • 1
  • 1
  • 2

4 Answers4

6

The function you are after is iconv() - from the user notes, this seems to be what you want to do: characters transliteration

danp
  • 14,876
  • 6
  • 42
  • 48
  • When I used iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $str); to convert João, it returened Joo I would like it to return Joao... – castor Mar 02 '10 at 09:13
  • Make sure the string is truly UTF-8. Encoding could be why it's not working as expected. – Matthew Mar 02 '10 at 09:18
  • Isn't there a script that changes everything (all type of formattings) to plain english. I can't get the code to work :( – castor Mar 02 '10 at 09:27
  • `echo iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', "Jo\xc3\xa3o");` Note that I've hard coded the 'ã' as UTF-8 (0xc3a3) to ensure that the encoding is correct. – Matthew Mar 02 '10 at 19:03
4

You should use this one and it will works:

setlocale(LC_CTYPE, 'nl_BE.utf8');
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);

I've tested it a lot of accentuated characters

eggyal
  • 122,705
  • 18
  • 212
  • 237
0

If you don't like danp's solution (iconv), you could use strtr with a list of conversions. This page has a sample script (first Google result).

Matthew
  • 47,584
  • 11
  • 86
  • 98
0

You could make a function holding a array of chars you want exchanged and pass strings through and just change ã to a that way, if iconv() doesn´t work out for you.