I have a JSON file, accessed remotely from a third-party website. It contains strings with special characters such as these:
"name":"StatTrak\u2122 FAMAS | Pulse",
and "name":"\u2605 Butterfly Knife | Case Hardened",
However, when I echo these values using the following PHP code:
$url = "https://www.example.com";
$json = file_get_contents($url);
$obj = json_decode($json);
$descriptions = $obj->rgDescriptions;
foreach ($descriptions as $key => $value) {
echo htmlspecialchars($value->name);
echo htmlspecialchars($value->name, ENT_QUOTES, 'UTF-8');
}
It prints these lines as:
StatTrakâ„¢ FAMAS | Pulse
and ★ Butterfly Knife | Case Hardened
How can this be prevented? This also occurs when storing these values in a MySQL table.
I have also tried the following:
$enc = mb_detect_encoding($value->name, "UTF-8,ISO-8859-1");
echo (iconv($enc, "UTF-8", $value->name) . ",");
But the results are the same.