Reputation: 37377
I thought utf-8 would be able to handle just a neat £
instead of having to convert to entities?
What's the proper way of handling the GBP symbol with UTF-8 and HTML5?
(ps. don't think the html5 part should make any difference)
update:
Here's test document:
<!doctype html>
<head>
<meta charset="utf-8">
<title>GBP Test</title>
</head>
<body>
£55
<br />
£55
</body>
Thanks everyone for your help.
For anyone else facing this frustration the issue comes with your text editor. Even Notepad formats in non utf-8.
SOLUTION:
Changed Read and Write formats to UTF-8 in my text editor (PHP Designer)
Upvotes: 5
Views: 5078
Reputation: 165201
The short answer is that you don't need to use entities for most characters as long as you declare the documents character set to UTF-8
(using either a Content-Type
header, a meta
charset
element in the head, or an xml
encoding
attribute with XHTML)...
The only characters you NEED to encode in a UTF-8 HTML document are (Depending on the context):
&
=> &<
=> <>
=> >"
=> "And if you are using XHTML (which is also valid XML), you also need to encode single quotes with either (again, depending on the context):
'
=> ''
=> ''
=> '(Note that the last 2 are preferred, since '
is not defined in HTML...)
Also note that &, < and > need to be escaped everywhere, and " and ' only need to be escaped inside of the appropriate attribute (so if an attribute is quoted using "
, you'd need to escape all other "
characters inside of that attribute)...
See the HTML 5 Draft for more information...
Upvotes: 4
Reputation: 449525
Just use the character. It will work fine.
The symbol has a different code point in UTF-8 than in ISO-8859-1 of course. A ISO-8859-1 encoded pound sign will not work in UTF-8, and vice versa. You'd have to convert it.
Related: When Should One Use HTML Entities
Upvotes: 4