Get part of a website

Asked

Viewed 54 times

-1

  • 1

    Possible duplicate of How can I get the lottery results?

  • see the script for that answer: http://answall.com/a/47605/4793 The logic is the same. Just change the URL

  • I don’t understand very well, can you give me an example with the code so I can understand better? Thank you.

  • I believe it is exact duplicate of this (after all, only changes the origin of the data): Receive external JSON data from PHP.

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'];
?>

That is, we access the URL with file_get_contents and decoded the JSON, which will become a array. Therefore, we assign the value of array corresponding to the average price at the variable you want :)

PS: Through print_r it is possible to view the array generated from JSON to get the correct value to use in the brackets

print_r ($decode);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.