1

I can see that htmlspecialchars() or htmlentities() convert special characters like & " to & " which isn't quite I am looking for.

My database table stores text articles that when I fetch and display, anything that contains special characters do not display in a readable format.

Any PHP (Codeigniter) function that accomplishes this?

Added

Sorry for not being so clear about my question. My case is that I have a word it's and this displays as it’s

Seong Lee
  • 10,314
  • 25
  • 68
  • 106
  • What *are* you looking for then? What problem do you have exactly? What characters do you define as "special"? – deceze Aug 14 '13 at 11:32
  • @deceze it can be any of those special characters. I cannot simply pick one or two as any variery can come up in the future. Thanks for your input. – Seong Lee Aug 14 '13 at 11:39
  • Can you please give an example of a **special** character? – Anshu Dwibhashi Aug 14 '13 at 11:41
  • 1
    I recommend this article for reference: http://kunststube.net/encoding/. – Expedito Aug 14 '13 at 11:41
  • Wait a minute... Your *special* characters (`&` and `"`) are only special in HTML context—they're encoded exactly the same in all popular encodings. Why isn't `htmlspecialchars()` what you are looking for? – Álvaro González Aug 14 '13 at 11:41
  • @ÁlvaroG.Vicario using htmlspecialchars("&") will give me `&`. My case is that I have `it's` and this displays like `it’s`. `` solved it! – Seong Lee Aug 14 '13 at 11:45
  • 1
    Why didn't you say so in the question?! http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – deceze Aug 14 '13 at 11:46
  • Right, then it's a dupe after all. Too bad you cannot vote again after retracting a vote. Whatever, printing a literal `&` as `&` will generate **invalid HTML**. – Álvaro González Aug 14 '13 at 11:48
  • Sorry for the confusion. I edited my question so it is a bit clearer. – Seong Lee Aug 14 '13 at 11:51

2 Answers2

2

Perhaps you should check the charset of your output. For example use <meta charset="UTF-8"> in your html-document. [reference].

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
bastey
  • 668
  • 2
  • 11
  • 17
-1

Try base64_encode() it.

$newStr = base64_encode("some texrt");

And by read, use base64_decode().

Set your mysql database to utf8:

SET NAMES utf8
m1k1o
  • 2,344
  • 16
  • 27