A common problem when accepting input containing the Danish letters "æ, ø & å" is converting them to the proper HTML codes. The following function uses a very simple approach. The function simply takes in a string, uses regular expressions to replace the letters with the proper HTML code and then returns the new string. This function can obviously be extended into replacing other special characters as well.
function replcSpecChar($string){
$string = preg_replace("æ", "æ", $string);
$string = preg_replace("ø", "ø", $string);
$string = preg_replace("å", "å", $string);
$string = preg_replace("Æ", "Æ", $string);
$string = preg_replace("Ø", "Ø", $string);
$string = preg_replace("Å", "Å", $string);
return $string;
}
On a sidenote, in HTML5 the default character encoding is UTF-8. This can be included in the
section with the code:HTML codes for æ, ø & å
æ: æ
ø: ø
å: å
Æ: Æ
Ø: Ø
Å: Å