0

I have have string in php as follows:

shows that he/she is a firm believer in “If it ain’t broke, don’t fix it” or “leave well enough alone”

when I print this string it output something like this:

shows that he/she is a firm believer in “If it ain’t broke, don’t fix it†or “leave well enough aloneâ€

How can i print this exactly as the first one? is there any solution?

arti
  • 21
  • 5
  • put your code please – Ayyanar G Mar 25 '15 at 07:26
  • "; print_r($text); exit; ?> – arti Mar 25 '15 at 07:28
  • This has nothing to do with quotes, it has to do with encodings. Your "quotes" are not plain standard `'` characters, they're fancier Unicode quotes. You need to learn how to handle encodings correctly. Start here: [What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text](http://kunststube.net/encoding/), [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/), [The Great Escapism (Or: What You Need To Know To Work With Text Within Text)](http://kunststube.net/escapism/) – deceze Mar 25 '15 at 07:40

2 Answers2

2

Ensure that your source code file uses the same charset as the browser interpreting your file. For example if you store your source code as utf-8, be sure to tell the browser to use utf-8 too:

<meta charset="utf-8">

If the text comes from a database or a file, ensure the table/file uses the same charset too.

Mario A
  • 3,286
  • 1
  • 17
  • 22
-1

try with,

print_r(utf8_encode($text));
Ayyanar G
  • 1,545
  • 1
  • 11
  • 24
  • It works fine in this case. But what to do if the same text we are importing from excel file? – arti Mar 25 '15 at 10:24