Why doesn't the translation work?

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

makes a mistake ...

should print: myresume

+3
source share
1 answer

It depends on the iconv library.

In Ubuntu 10.10, I get the following:

$ 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 icon:

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 performed by iconv is not consistent between implementations. For example, the glibc implementation transliterates éto e, but libiconv translites it to 'e.

Until we have ICU transliterator support in PHP (due to the next version), there will be no reliable way to reliably perform these conversions (although if you want to remove tags, there are other solutions ). In the PHP development version, with the intl extension, you can do the following:

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

which gives

Nadales myresume
+2
source

Source: https://habr.com/ru/post/1793187/


All Articles