Recently I needed to have a drop down box for countries. In english I just simply order by name but when you look at the german translation, ordering by name puts all the countries that have an umlaut character at the bottom. For example, I know the German translation for Austria is Österreich. So when I sort the translated names I now want this name to appear after the country named Oman. I know that the german umlaut html entity for ö is ö. I use that to get the character to sort the countries with.
Here is the code using PHP.
foreach($country as $val){
$charset = htmlentities(utf8_decode($val['country_name']));
if(substr($charset, 0,1)== '&'){
$newcharset = str_replace(substr((html_entity_decode($charset)), 0,1),
substr($charset, 1,1), html_entity_decode($charset));
$origcountry[$val['country_id']] = $val['country_name'];
$testarr[$val['country_id']]= $newcharset;
$swap[$val['country_id']] = $newcharset;
}else{
$testarr[$val['country_id']] = $val['country_name'];
}
}
asort($testarr);
foreach($testarr as $ckey=>$val){
if($key= array_search($val, $swap)){
$newcountryarr[$ckey] = $origcountry[$key];
}else{
$newcountryarr[$ckey] = $val;
}
}