I'm trying to make a transliteration using PHP, but what I need is the conversion of all non-latin characters but keep the italian accented characters (àèìòù).
PHP Transliterator lacks of documentation and on-line examples.
I've read the ICU docs and I know that there is a rule that force Transliterator to convert a char into another specified by us (à > b
).
The code (using the create
funciton)
$str = "AŠAàèìòù Chén Hǎi yáo München Faißt Финиш 国内 - 镜像";
$transliterator = Transliterator::create("Any-Latin; Latin-ASCII");
echo $transliterator->transliterate($str);
converts all non-latin chars into latin (with all the accented chars) and gives the result
ASAaeiou Chen Hai yao Munchen Faisst Finis guo nei - jing xiang
and the code (using createFromRules
function)
$str = "AŠAàèìòù Chén Hǎi yáo München Faißt Финиш 国内 - 镜像";
$transliterator = Transliterator::createFromRules("á>b");
echo $transliterator->transliterate($str);
forces correctly the conversion of à
into b
, but, obviously, without the conversion Any-Latin; Latin-ASCII
made by the previous code, giving the result
AŠAbèìòù Chén Hǎi ybo München Faißt Финиш 国内 - 镜像
So my goal is to merge the Any-Latin; Latin-ASCII
conversion and the à > à
rule (and the other italian accented vowels), in order to tell Transliterator to convert all non latin chars to latin, but convert italian accented vowels into themselves, with the following result:
ASAàèìòù Chen Hai yao Munchen Faisst Finis guo nei - jing xiang
Is there a way to put the à>à
rule in the create
function's parameter or add the Any-Latin; Latin-ASCII
directive in the createFromRules
function's parameter?