A function to convert UTF-8 to best-fit ASCII. Handles punctuation too. Characters it doesn't understand get converted to '?'.
<?php
function utf8_to_ascii($text) {
if (is_string($text)) {
$text = preg_replace_callback('/\X/u', __FUNCTION__, $text);
}
elseif (is_array($text) && count($text) == 1 && is_string($text[0])) {
$text = iconv("UTF-8", "ASCII//IGNORE//TRANSLIT", $text[0]);
if ($text === '' || !is_string($text)) {
$text = '?';
}
elseif (preg_match('/\w/', $text)) { $text = preg_replace('/\W+/', '', $text); }
}
else { $text = '';
}
return $text;
}
$text = 'Française señor café 0123 කොහොමද ශ්රී ලංකා hello Žluťoučký kůň '
. 'ÀÁÂ,ÃÄÅ,Æ,ÇÈ,ÉÊË,ÌÍÎ,ÏÐÑ,ÒÓÔ,ÕÖØ,ÙÚÛ,ÜÝ,Þ,'
. 'ß,àáâ,ãäå,æ,çèé,êëì,íîï,ðñò,óôõ,öøù,úûýý,þ,ÿŔŕ '
. 'YA(亚) HE(何) Tra Mỹ';
print(utf8_to_ascii($text));
?>