0

HTML is stored in the DB. £ sign is stored as £ and renders correctly in 1252 however when I change the page encoding to utf-8 renders incorrectly ?

I know its a simple issue.. ?

Christian Hayter
  • 30,581
  • 6
  • 72
  • 99
Youeee
  • 383
  • 3
  • 19
  • Care to elaborate on what you are using to display it? – James Wiseman Dec 21 '09 at 13:58
  • We need to know: (a) what is your DB, (b) what is your programming language, (c) the code that writes the data, (d) the code that reads the data. Otherwise no help will be forthcoming. – Christian Hayter Dec 21 '09 at 14:14
  • There isn't enough information to answer your question in detail - what programming language are you using? What are you using for display? What DB are you storing into? What is the code that puts it in the DB? The code that takes in out of the DB? – Oded Dec 21 '09 at 14:15
  • ok code is in classic asp with a sql 2005 backend. using ado2.8 to read from the DB. just responding it out to the screen. – Youeee Dec 21 '09 at 14:24
  • @Yucel: Thanks for that. Next question - what is the data type of the table column that you are storing the text in? – Christian Hayter Dec 21 '09 at 14:44

8 Answers8

1

If your database encoding is not UTF-8, or if the application does not retrieve data from the database as UTF-8, data stored in the database will not render correctly. What is the database, what is your application platform?

cdonner
  • 37,019
  • 22
  • 105
  • 153
0

You need to ensure that both the DB server and connection to it are UTF8 enabled. What DB and web server are you using?

marpetr
  • 183
  • 6
0

You could replace with:

£ or £

http://www.w3schools.com/tags/ref_entities.asp

Also make sure that you have set the charset and encoding to utf-8.

http://www.utf8.com/

Josh Barker
  • 1,203
  • 1
  • 11
  • 28
0

This Stack Overflow thread describes how to use UTF-8 + MySQL + PHP: Strategy for supporting unicode & multi language in PHP5

Also, make sure you’re using the correct htmlentities() parameters when working with UTF-8 strings.

Update: I’ve just noticed you updated your post (tags) to show that you’re using ASP (not PHP), but I guess the answer still goes. Make sure the database tables and fields as well as the connection to that database are set to UTF-8, and make sure you’re correctly handling UTF-8 strings in your application.

Community
  • 1
  • 1
Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
0

I'm not so sure that classic ASP uses UTF8 as its default string type (like .net does), so you may be able to simply change the page to ISO-8859-1 and it will work.

mike nelson
  • 21,218
  • 14
  • 66
  • 75
0

What collation sequence is your SQL Server using for the column, and what code page is in use on the system? It will convert the incoming data to something that can be stored in that character set, and that might not be valid for what you want to get back. My company's product accidentally translated 'ü' into '÷' until we straightened this out.

DaveE
  • 3,579
  • 28
  • 31
0

What needs to be done to use UTF-8 properly in ASP.

  • Your page needs to be saved as UTF-8 (if it contains any non-ASCII characters).
  • Any serverside script must contain only ASCII characters
  • Your page should start with line <%@ codepage=65001 %>
  • Your serverside script must do this:- Response.CharSet = "UTF-8"

That said I would strongly recommend against storing HTML in a DB unless you really building some kind of CMS and/or have some rigourous vetting procedures in place.

My guess is you've forgotten to do one of the last two bullet points.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
0

have you saved the chars as unicode in the DB ?

when inserting unicode data in a nvarchar fields always preceed the string with N as in insert into table (stringfieldname) values (N'data to be inserted') which will ensure the correct storing of the data ...

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317