Karem
Karem

Reputation: 18123

HTML in JSON, use utf8_encode but kills some characters?

To make it short I am receiving HTML through some json, in an ajax jquery call. response.html

Now for this html, after file_get_contents() and some filters, I am wrapping it with utf8_encode() to make it able to transfer with JSON and not make some of the syntax break the JSON. I found out that I should do this, thanks to Putting HTML in JSON

It all works fine until I have the danish, swedish characters: öäå

It makes these: öäå . How can I fix this? Is there another way to escape the html string?

My Response header is utf-8.

enter image description here

Upvotes: 2

Views: 314

Answers (1)

Ja͢ck
Ja͢ck

Reputation: 173662

The utf8_encode() function should only be used for ISO-8859-1 data.

If you already have UTF-8 encoded data, you will see the following transformation:

c3b6 c3a4 c3a5             (öäå)

c383c2b6 c383c2a4 c383c2a5 (öäå)

Either you have to make sure the read data is ISO-8859-1 or don't apply utf8_encode().

Upvotes: 1

Related Questions