views:

87

answers:

4

’ showing in page in place of this '

what is the problem? how to solve

This is already defined in

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Update:

Browser is already set on Unicode

alt text

And content type is already set too

alt text

+2  A: 

Ensure the browser is using UTF-8 encoding instead of ISO-8859-1/Windows-1252.

Or use &rsquo;.

KennyTM
"Or use ’" . problem is solved.
metal-gear-solid
No, it is not solved. There's still an inconsistency in character encoding in your application. You will re-encounter the same problem in the future for other non-CP1252 characters. And there's quite a lot of them ...
BalusC
@BalusC -Thanks for this info.
metal-gear-solid
@jitendra This is a hacky workaround and doesn't solve the problem. I recommend you work through the steps provided in @BalusC's very good answer.
Pekka
@Pekka - I don't know server side and database programming so i used this workaround. and i don't have access to server. I appreciate @BalusC effort.
metal-gear-solid
@jitendra I see. Still, this should get solved properly by fixing the database connection.
Pekka
How to write html <code>tags</code> in comments?
metal-gear-solid
Markdown just works in comments the same way. Use ` to start and end code.
BalusC
Thanks very much @BalusC
metal-gear-solid
+2  A: 

If your content type is already UTF8 (are you sure this is the case? Check Firefox's "content type" menu and what is checked there) , then it is likely the data is already arriving in the wrong encoding. If you are getting the data from a database, make sure the database connection uses UTF-8.

If this is data from a file, make sure the file is encoded correctly as UTF-8. You can usually set this in the "Save as..." Dialog of the editor of your choice.

If the data is already broken when you view it in the source file, chances are that it used to be a UTF-8 file but was saved in the wrong encoding somewhere along the way.

Pekka
firefox setting is this see image http://shup.com/Shup/299367/110219131950-My-Desktop.png
metal-gear-solid
@jitendra good, so that is excluded. What is important now is where the data comes from.
Pekka
data coming from WYSIWYG editor
metal-gear-solid
@jitendra Yes but how is it stored?!?
Pekka
@Pekka - in database.
metal-gear-solid
@jitendra then you need to check whether the database connection is using UTF-8.
Pekka
+6  A: 

what is the problem?

It's an which has been encoded as CP-1252 instead of UTF-8.

how to solve?

Use UTF-8 instead of CP-1252 to read/write/store/display the characters.

This is already defined in

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

This only instructs the client which encoding to use to display the characters. This doesn't instruct your own program which encoding to use to read/write/store/display the characters. The exact answer depends on the server side platform / database / programming language used.

Update:

Browser is already set on Unicode And content type is already set too

Once again, this information is irrelevant. As said, this only instructs the client which encoding to use to display the characters. But the actual problem is that you're already sending ’ to the client instead of . The client is correctly displaying ’ as ’ using UTF-8 encoding. If the client was instructed to use for example ISO-8859-1, you would likely have seen ââ¬â¢ instead.

Here are some more links to learn more about the problem:

ASP.NET MVC environments are already by default UTF-8. But if you're actually using it, then there's something really messed up.

Update 2: as per the comments, the data is coming from a database. You need to verify with an independent DB admin tool how the data look like. If the is there, then you need to instruct the database connector to use UTF-8 as character encoding. If it already contains ’, then likely the database itself needs to be instructed to store the data as UTF-8. To achieve this, usually creating/altering the database and table as UTF-8 is sufficient. Here's a MySQL targeted example (copied from this article):

CREATE DATABASE db_name CHARACTER SET utf8;
CREATE TABLE tbl_name (...) CHARACTER SET utf8;

But if it is already UTF-8, then you need to take a step back. Who/what did store the data there? The problem is in there. Maybe it was stored from request parameters? If so, then you need to configure the request encoding.

BalusC
+1 for ur very good effort
metal-gear-solid
It's however sad to see that you after all didn't fix the problem, but just workaround the problem. This is a pretty major problem which should not be workarounded. Don't you consider yourself as a *good* developer?
BalusC
you mean i can use "'" as "'" while writing content no need to replace this ' with ’.
metal-gear-solid
A: 

You have a mismatch in your charecter encoding, you string is encoded in one encoding UTF-8 and what ever is interprating this page is using another say ASCII.

Alway specify your encoding in your http headers and make sure this matchs you frameworks definition of encoding sample http header

Content-Type    text/html; charset=utf-8

Setting Encoding in asp.net

<configuration>
  <system.web>
    <globalization
      fileEncoding="utf-8"
      requestEncoding="utf-8"
      responseEncoding="utf-8"
      culture="en-US"
      uiCulture="de-DE"
    />
  </system.web>
</configuration>

Setting encoding in jsp

David Waters