Upper case swedish words containing åäö
This function makes all characters upper case, even the swedish åäö.
But the most convenient way to do this is to use mb_strtoupper or mb_strtolower, available in PHP 4 >= 4.3.0 or PHP 5.
<?php
function com_dir_ucwords_swe($string){
$string = utf8_decode($string); //maybe not necessary
$string = strtolower($string);
$string = ucwords($string);
$search = array ('/Å/','/Ä/','/Ö/');
$replace = array ('å','ä','ö');
$string = preg_replace($search, $replace, $string);
$string_array = explode(' ', $string);
foreach ($string_array as $key => $value) {
$first_ascii = ord($string_array[$key][0]);
if ($first_ascii == 229 OR $first_ascii == 228 OR $first_ascii == 246) {
$string_array[$key] = substr_replace($string_array[$key], chr($first_ascii-32),0, 1);
}
}
$string = implode(' ', $string_array);
$string = utf8_encode($string);
return $string;
}
?>