PHP Transliteration

This will convert as much as possible foreign characters (including Cyrillic, Chinese, Arabic etc.) to their A-z equivalents:

$AzString = transliterator_transliterate('Any-Latin;Latin-ASCII;', $foreignString);

You might want install PHP Intl extension first.


You can use iconv, which has a special transliteration encoding.

When the string "//TRANSLIT" is appended to tocode, transliteration is activated. This means that when a character cannot be represented in the target character set, it can be approximated through one or several characters that look similar to the original character.

-- http://www.gnu.org/software/libiconv/documentation/libiconv/iconv_open.3.html

See here for a complete example that matches your use case.


If you are stuck with an development&release environment that doesn't support PHP 5.4 or newer, you should either use iconv or a custom Transliteration library.

In case of iconv, I find it extremely unhelpful especially using it on Arabic or Cyrillic alphabets. I would go for a PHP 5.4 built-in Transliteration class or a custom Transliteration class.

One of the solutions posted mentioned a custom library which I did not test.

When I was using Drupal, I loved their transliteration module, that I've recently ported it to make it usable without Drupal.


You can download it here and use as follows:

<?php

include "JTransliteration.php";

$mombojombotext = "誓曰:『時日害喪?予及女偕亡。』民欲與之偕亡,雖有";
$nonmombojombotex = JTransliteration::transliterate($mombojombotext);

echo $nonmombojombotex;

?>

If you are using iconv then make sure your locale is set correctly before you try the transliteration, otherwise some characters will not be correctly transliterated

setlocale(LC_CTYPE, 'en_US.UTF8');