Search code examples
phpfile-get-contentspartial

file_get_contents doesn't return everything


I'm trying to return a full json pattern from the steamcommunity market. unfortinuatly it only returns the 1st patern.

It should return : {"success":true,"lowest_price":"$0.63","volume":"5,301","median_price":"$0.68"}

Instaid it only returns {"success":true}

<?php
$hash = "AK-47 | Elite Build (Minimal Wear)";
$marketObj = json_decode(file_get_contents("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=$hash"), true);
        if ($marketObj['success'] !== true) {
            echo jsonErr('An error occured while fetching market price for an item.');
            return;
        }else {
            echo ($marketObj['lowest_price']);
        }
?>

so the problem is that i cant read the other parameters in my script. Anyone got a clue?


Solution

  • You need to urlencode() the query string because it has special characters it in:

    $hash = urlencode("AK-47 | Elite Build (Minimal Wear)");
    

    Alternatively, you could do something like this:

    $url = 'http://steamcommunity.com/market/priceoverview/?' . http_build_query([
        'currency' => '1',
        'appid' => '730',
        'market_hash_name' => 'AK-47 | Elite Build (Minimal Wear)',
    ]);
    $marketObj = json_decode(file_get_contents($url), true);