-1

Actually I'm facing the problem while I fetch data from my database on localhost. The database contain lines with special characters.

Such as - "You've done a Good Job".

But when I fetch the data using echo $row['lines']; it comes with "You?ve done a Good Job".

Anyone please help me how to overcome with this issue.

Provash Shoumma
  • 441
  • 1
  • 5
  • 7

4 Answers4

2

I suspect this text doesn't actually use the ' character, but instead the fancy left single quotation mark , which is a Unicode character and is not available in all character sets. So, if you're using a non-Unicode character set, it'll freak out and represent it as a ?

This issue could be in a few different places in your code, but a few to check are:

  • Is your database using UTF8?
  • Is your HTML using UTF8 encoding, like <meta charset='utf-8'>?

And maybe a few others. Mostly, check the whole pipeline and make sure it's UTF-8 through and through.

Matchu
  • 83,922
  • 18
  • 153
  • 160
  • Exactly. I didn't notice it. I find now that the character is actually left single quotation mark. Thank you very much. Could you please tell me what shall I do now? – Provash Shoumma Jul 16 '13 at 08:50
1

Check your database encoding, check your connection encoding in php, check your php-page encoding. First two should match. If page encoding doesn't match db encoding, you should consider using iconv or mb_convert_encoding function.

Also there should be correct meta tag if you are using html, like

<meta charset='utf-8'>

or

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

Plus it will be great if you send correct headers from php:

header('Content-type:text/html;charset=utf-8');
mr. Pavlikov
  • 982
  • 5
  • 7
0

Looks like an encoding problem. Try using...

$row["lines"] = utf8_encode($row["lines"]);

... and make sure you have utf-8 encoding enabled in your website.

cheesetor
  • 91
  • 3
0

What I don't recommend is trying to use something like HTML encoding before entering it into the database. One problem with that is it makes it more difficult to access your data, such as retrieving results alphabetically.

What I do recommend is switching everything to UTF-8. That means:

  • All of your database tables
  • Any editor that you use
  • The meta tags in the pages that display your data
Expedito
  • 7,771
  • 5
  • 30
  • 43