-1

I'm grabbing some json data from a URL like this one: https://steamcommunity.com/id/itemdepot3/inventory/json/730/2

$json = json_decode(file_get_contents(
"https://steamcommunity.com/id/itemdepot3/inventory/json/730/2"),true);

I'm then trying to print the names of each item:

foreach($json["rgInventory"] as $item){
    $cid = $item["classid"];
    $iid = $item["instanceid"];
    $name = $json["rgDescriptions"]["{$cid}_{$iid}"]["market_name"];        
    echo $name;
}

But the names which should include a ™ come out mangled like this:

StatTrakâ„¢ Five-SeveN | Nightshade (Field-Tested)

I've tried a bunch of goofy regex fixes (as this is the only character I need to fix) but to no avail. I have no idea what kind of encoding I'm dealing with here and all my searches have come up dry. How can I get my ™ symbols to print correctly?

deceze
  • 510,633
  • 85
  • 743
  • 889
ReallyMadeMeThink
  • 1,061
  • 7
  • 11

1 Answers1

2

As discussed in the comments above, you need to make sure you specify the correct output encoding.

The problem stems from the fact you were outputting UTF-8 characters, but your web browser was trying to decode the page as a single-byte character set (Most likely ISO-8859-1 or Windows-1252).

Make sure that you always specify the output encoding via the appropriate use of HTTP headers (in this case Content-Type: text/html; charset=utf-8) or through the use of a <meta> tag.

Phylogenesis
  • 7,775
  • 19
  • 27