I\'m looking for way to convert chars like āžšķūņrūķīš to azskunrukis. In other words, to replace ā with a, ž with z an
Take a look at iconv's transliteration capabilities:
<?php
$text = "This is the Euro symbol '€'.";
echo 'Original : ', $text, PHP_EOL;
echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL;
echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL;
echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;
?>
The above example will output something similar to:
Original : This is the Euro symbol '€'.
TRANSLIT : This is the Euro symbol 'EUR'.
IGNORE : This is the Euro symbol ''.
Plain :
Notice: iconv(): Detected an illegal character in input string in .\iconv-example.php on line 7
This is the Euro symbol '
Your example text can be tranliterated using:
$translit = iconv('UTF-8', 'US-ASCII//TRANSLIT', 'āžšķūņrūķīš');
Here's an example with the text you provided: http://ideone.com/MJHvf
As an alternative to iconv
, you could check out the Normalize functions of the intl extension (if available).
I'm not sure of any functions that do this directly, but there are some implementations of translation tables that do something like that in the comments on strtr's documentation page. They end up using a table that directly translates each character to its equivalent, i.e. "ž" => "z".