Nis Bornoe

PHP: Danish letters "æ, ø & å"

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 returning the new string. This function can obviously be extended into replacing other special characters as well.


function replcSpecChar($string){
  $string = ereg_replace("æ", "æ", $string);
  $string = ereg_replace("ø", "ø", $string);
  $string = ereg_replace("å", "å", $string);
  $string = ereg_replace("Æ", "Æ", $string);
  $string = ereg_replace("Ø", "Ø", $string);
  $string = ereg_replace("Å", "Å", $string);
	
  return $string;
}

On a sidenote, when using "æ, ø & å" you should probably use the character set (charset) iso-8859-1. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

HTML codes for æ, ø & å

æ &aelig;
ø &oslash;
å &aring;
Æ &AElig;
Ø &Oslash;
Å &Aring;

FacebookLinked In Valid XHTML 1.0 Transitional Valid CSS!

hit counter joomla
eXTReMe Tracker