Ilu
Ilu

Reputation: 75

get utf8 from json in PHP

I have a JSON:

$json = "{"guid": 1, "cid": 644, "lastest": [{"stt": 1, "uid": 111, "created": 1427168366, "update": 780, "content": "qu\\xc3\\xaa t\\xc3\\xb4i", "cname": "mvd", "parentid": 0, "highlight": 0}]}"

$arr =json_decode($json, true)
echo $arr['lastest'][0]['content'].

it showing qu\\xc3\\xaa t\\xc3\\xb4i.

But I want to show "quê tôi".

At header, I set:

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

What to do? Thanks very much!

Upvotes: 0

Views: 56

Answers (1)

Pratik Boda
Pratik Boda

Reputation: 414

I tried Below on my localhost and I got your solution

<?php 
header('Content-Type: text/html; charset=utf-8');
echo "qu\xc3\xaa t\xc3\xb4i";

//I removed backshlash qu\\xc3\\xaa t\\xc3\\xb4i -> qu\xc3\xaa t\xc3\xb4i
?>

But there is still problem in json May be Bassem Lhm is right about encoding

Upvotes: 1

Related Questions