user380603
user380603

Reputation: 183

Why does £ turn to A using xhtml and css

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

Upvotes: 1

Views: 74

Answers (1)

Paul Dixon
Paul Dixon

Reputation: 301135

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">

<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">

<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 ã

Upvotes: 3

Related Questions