I receive some generated json files and some files would contain the ™ symbol, if the file has that then json_decode
won't work on it, when I print $data
NULL will be printed. If I manually remove the symbol then I will see the data. I am using the below code and it will print out what is in the json file until it gets to the json file that has the ™ symbol
$json = file_get_contents($count . '.json');
$data = json_decode($json);
echo '<pre>';
var_dump($data);
echo '</pre>';
I have tried using urlencode
and urldecode
and htmlspecialchars
but they don't work either.
json_decode will only parse UTF-8 strings. If the file you are reading is not UTF-8 format it will fail.
If you do not know the encoding of the file you will be reading, there are ways to convert the data to UTF-8 before parsing it as shown in this post:
PHP: Convert any string to UTF-8 without knowing the original character set, or at least try