Brendan Mullan
Brendan Mullan

Reputation: 13

PHP json_decode() with accents doesn't work

I have a JSON array that saves some accented characters in it, a value could be üna. Saving this as JSON i use json_encode($array, JSON_UNESCAPED_UNICODE); which works correctly, however when trying to display on the page with json_decode() it will not show because of the accent.

$arr = json_decode($array, true);
print_r($arr);

I have tried adding the JSON_UNESCAPED_UNICODE to that aswell as adding a UTF-8 header line but nothing will print out.

Upvotes: 0

Views: 2076

Answers (1)

Elias Gomes
Elias Gomes

Reputation: 21

JSON_UNESCAPED_UNICODE Encodes multibyte Unicode characters literally, this will do it

$arr=array("üna","&8*");
$encode_json = json_encode($arr,JSON_UNESCAPED_UNICODE);
print_r($encode_json);
$decode_json=json_decode($encode_json);
print_r($decode_json);

Upvotes: 1

Related Questions