tags:

views:

45

answers:

1

Hello,

I have noticed when i put a £ sign in it turns out to be a A when i look at my website in firefox. Do you know the reason why this is happening?

Thanks

+3  A: 

it sounds like you've got a page encoded in UTF-8, but being displayed as Latin-1 - make sure the meta tags and/or server headers tell browser what encoding the page uses.

In an XHTML file, you need to declare the encoding in the initial XML tag, and for maximum compatibility, include a meta tag also

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
    ...
  </head>

Bobince suggests in a comment that for maximum backwards compatibility you do something like this

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    ...
  </head>

If you're curious why you get strange letters, here's the likely explanation...

  • The pound sign is Unicode character U+00A3
  • This is encoded in UTF-8 as the two byte sequence C2 A3
  • if you interpreted that as Latin-1, you'd get ã
Paul Dixon
You don't need the XML Declaration (XHTML files parsed as XML rather than HTML are UTF-8 by default), and you shouldn't include it as it will trip IE6 into Quirks Mode. If you are serving the file as `text/html` as most people do for IE compatility, the `Content-Type` meta should match that.
bobince
Thanks - have modified answer.
Paul Dixon