Good day to all. Working with the Steam API, got an array of data. I displayed them on the screen with the code:

$all_items = file_get_contents("ссылка"); print_r($all_items); 

Received:

 "items_game" { "game_info" { "first_valid_class" "1" "last_valid_class" "1000" "first_valid_item_slot" "0" "last_valid_item_slot" "15" "num_item_presets" "4" } "store_currency_pricepoints" { "10" { "GBP" "8" "EUR" "9" "RUB" "700" "BRL" "33" "JPY" "1100" "NOK" "90" "IDR" "134900" "MYR" "40" "PHP" "500" "SGD" "14" "THB" "400" "VND" "250000" "KRW" "12000" "TRY" "30" "UAH" "120" "MXN" "180" "CAD" "13" "AUD" "15" "NZD" "15" "CNY" "100" "TWD" "300" "HKD" "80" "INR" "700" "AED" "50" "SAR" "40" "ZAR" "140" "COP" "30000" "PEN" "40" "CLP" "6700" "CHF" "10" } 

The question is, is it possible to pull out the data and, for example, display only the data that carries the "first_valid_class" for example? I try through foreach (), but it gives an error that I enter not what I need. Can you please tell me how to get out of this array only the data that interests me?

  • And you did not think, well, I do not know, convert the string to JSON? Although not like him. Show that returns file_get_contents . String, not a picture, soc. Some kind of network: "Here are some photos of my code!". - user207618
  • @Other here, edited. - Bim Bam
  • Honestly, I don’t even know what led those who created such an answer. I would add it to valid JSON and then already json_decode to help. - user207618
  • @Other, this is Steam, more than 10,000 lines. So, you can not get data from here? - Bim Bam
  • one
    Check for a start in the response format documentation. A quick appeal to Google says that steam api can give json (default), xml and vdf (some kind of its own format with its parser). Your piece is just like vdf - Shallow

1 answer 1

Like that:

 $all_items = file_get_contents("ссылка"); $json = json_decode($all_items); echo $json->items_game->game_info->first_valid_class; 

As far as I remember, the Steam API returns a valid json, if we supplement the link with the parameter &format=json

You can use the https://github.com/rossengeorgiev/vdf-parser library to parse specifically your version with the vdf format - there are 140 lines of code. What in response to duplicate do not want.

  • Not an answer. The question returns is clearly not JSON. - user207618
  • In the example vdf: developer.valvesoftware.com/wiki/KeyValues, but nothing prevents you from requesting exactly json. The answer is not to the point, I agree. He for json option - iosp
  • Then you need to describe what you need to do to get JSON. In the current view, your code will always decode to null and crash with an error that it is impossible to select properties for null , which is logical. - user207618
  • Completed the answer. - iosp
  • Again, not a solution to a given question, but better. - user207618