dynamic
dynamic

Reputation: 48121

Why doesn't translit work?

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

makes error...

should print: myresume

Upvotes: 5

Views: 2421

Answers (1)

Artefacto
Artefacto

Reputation: 97835

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

Upvotes: 3

Related Questions