I created a clean function in PHP for a project to help construct useful URLs from database content. It removes any spaces and special characters, so that a sentence like "My Motörhead Albums" becomes in the URL my-motoerhead-albums. However, it seems to not correctly convert the umlauts like ö,ä,ü, etc, and I can't figure out why.
Here's the code:
function clean($text) {
$text = trim($text);
$text = strtolower($text);
$code_entities_match = array(
' ', '--', '"', '!', '@', '#', '$', '%', '^', '&',
'*', '(', ')', '_', '+', '{', '}', '|', ':', '"',
'<', '>', '?', '[', ']', '\\', ';', "'", ',', '.',
'/', '*', '+', '~', '`', '=', '¡', '¿', '´', '%C2%B4',
'ä', 'ö', 'ü', 'ß', 'å', 'á', 'à',
'ó', 'ò', 'ú', 'ù', 'í', 'é', 'è', 'ø', 'Þ', 'ð', '%C3%9E', 'þ'
);
$code_entities_replace = array(
'', '-', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'ae', 'oe', 'ue', 'ss', 'aa', 'a', 'a', 'o', 'o', 'u', 'u', 'i', 'e', 'e', 'oe', 'th', 'th', 'th', 'th'
);
$text = str_replace($code_entities_match, $code_entities_replace, $text);
return $text;
}