5
setlocale(LC_ALL, 'en_US.UTF8');
$string= 'ṃỹṛèşưḿĕ';
echo iconv('UTF-8', 'ASCII//TRANSLIT', $string);

makes error...

should print: myresume

Sampson
  • 265,109
  • 74
  • 539
  • 565
dynamic
  • 46,985
  • 55
  • 154
  • 231

1 Answers1

3

It depends on the iconv library.

In Ubuntu 10.10, I get this:

$ php -i | egrep "iconv (implementation|library)"
iconv implementation => glibc
iconv library version => 2.12.1
$ php a.php 
myresume

But on another machine using the GNU iconv:

iconv implementation => libiconv
iconv library version => 1.11
# php a.php 
Notice: iconv(): Unknown error (88) in /tmp/root/a.php on line 5

The transliteration done by iconv is not consistent across implementations. For instance, the glibc implementation transliterates é into e, but libiconv transliterates it into 'e.

Until we have support for ICU transliterators in PHP (due for the next version), there won't be a realiable way to reliable do these transformation (though if you only want to remove marks, there are other solutions). In the development version of PHP, with the intl extension, it's possible to do this:

<?php
$t = Transliterator::create("latin; NFKD; [^\u0000-\u007E] Remove; NFC");
echo $t->transliterate('Ναδάλης ṃỹṛèşưḿĕ');

which gives

Nadales myresume
Community
  • 1
  • 1
Artefacto
  • 96,375
  • 17
  • 202
  • 225