Get part of a site [closed]

-1

Well what I intended to do is get the part of a website with php and store it in a variable $ price_media.

Well the link is as follows: link

From this link I wanted to get the value of "median_price": "$ 0.03" and store in that variable of $ price_media.

How can I do this?

Thank you.

    
asked by anonymous 06.03.2016 / 23:05

1 answer

2

It is possible with the following code:

<?php

  $url = "http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=M249%20|%20Contrast%20Spray%20(Field-Tested)";  
  $json = file_get_contents($url);  
  $decode = json_decode($json, TRUE);   

  $preco_medio = $decode['median_price'];
?>

In other words, we access the URL with file_get_contents and decode JSON, which will become an array . So, we assign the value of the array corresponding to the average price to the variable you want:)

PS: Through print_r you can view the array generated from JSON to get the correct value to use in the brackets

print_r ($decode);
    
07.03.2016 / 00:01