Search code examples
phpiconvtransliteration

Azerbaijani to ASCII Transliteration


Is there anything in PHP that will convert the Latin form of Azerbaijani to ASCII, i.e. removing characters unique to the country.

e.g.

Məmmədhəsənov => Mammadhasanov 

Solution

  • There is just the one character that is not handled by the Transliterator class:

    Solution:

    $str = 'Məmmədhəsənov';
    $str = preg_replace( '~ə$~', 'eh', $str );
    $str = str_replace( array( 'Ə', 'ə' ), array( 'A', 'a' ), $str );
    $t = Transliterator::create("Latin-ASCII; NFKD; [^\u0000-\u007A] Remove; NFC");
    echo $t->transliterate($str);