Search code examples
phphtmlspecialchars

String with Æ Ø or Å is removed when using htmlspecialchars or htmlentities


I simply cannot figure out why my strings are being removed when I try to echo them out when they contain Æ Ø or Å.

I have tried both:

htmlspecialchars ($row ['contact_person'])
htmlentities ($row ['contact_person'])

I the contact persons name is Peter Mørk for example, the string is simply not showing. If I remove htmlspecialchars or htmlentities the string is echoed out fine.

Shouldn't the string just be encoded, instead of removed?

What do I need to do?


Solution

  • You can specify a third parameter to htmlspecialchars() which changes the character set. This works, for example:

    echo htmlspecialchars('Peter Mørk',null,'ISO-8859-1');