I have downloaded a data dump of my entire Facebook Messenger history in JSON format. I am trying to render messages in a basic PHP application but emojis and certain other characters are coming out like this:
I didnât get checked for id !!!
This is the corresponding JSON data:
"content": "I didn\u00e2\u0080\u0099t get checked for id !!!"
I have tried rawurldecode and utf8_decode, decodeURI and even a more complicated regex solution, but the characters keep rendering the same. I have also attempted to set UTF8 explicitly using PHP headers, but again no luck.
Here is my basic code:
$json = json_decode(file_get_contents('message_1.json'));
$messages = $json->messages;
$messages = array_reverse($messages);
foreach($messages as $m) {
if(!isset($m->content)) continue;
$ts = $m->timestamp_ms;
$date = date('d/m/Y', $ts / 1000);
echo "<strong>{$m->sender_name} ($date):</strong> $content<br>";
}
There are no errors and the messages render fine, except with any "\uXXX" characters being rendered incorrectly.
When parsing the following data:
"content": "I don\u00e2\u0080\u0099t have the key"
I would expect to see:
I don't have the key
However, my browser (Chrome) renders:
I donât have the key
Thank you in advance for any advice you can give!