蒸汽项目价格 - rawurlencode不工作?

时间:2015-12-31 02:44:07

标签: php urlencode

我真的很难用我的PHP脚本。它从数据库中获取了许多Steam市场项目名称,并试图从Steam市场获得价格。

当脚本生成链接时,它们似乎不起作用。但是,当我将它们手动放入浏览器时,它们可以正常工作。

我的代码(对不起,如果它粗糙 - 即时学习)

$sql = "SELECT * FROM `item_data` LIMIT 5";
$query = mysqli_query($conn, $sql);

foreach($query as $row) {
    echo $row['marketname'].'<br>';
    $itemname = rawurlencode($row['marketname']);
    echo $itemname.'<br>';
    $addy = "http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=".$itemname;
    $price = json_decode(file_get_contents($addy));
    if($price->success == 'true') {
        if($price->median_price) {
            echo intval(str_replace(str_split('$.'), '', $price->median_price));
        } else {
            echo 'No median price set.';
        }
    } else {
        echo 'Unable to retrieve price data.';
    }
    echo '<hr>';
}

这导致以下输出 -

Tec-9 | Isaac (Field-Tested)
Tec-9%20%7C%20Isaac%20%28Field-Tested%29
Unable to retrieve price data.
AUG | Ricochet (Battle-Scarred)
AUG%20%7C%20Ricochet%20%28Battle-Scarred%29
Unable to retrieve price data.
Glock-18 | Bunsen Burner (Minimal Wear)
Glock-18%20%7C%20Bunsen%20Burner%20%28Minimal%20Wear%29
Unable to retrieve price data.
MAG-7 | Seabird (Minimal Wear)
MAG-7%20%7C%20Seabird%20%28Minimal%20Wear%29
Unable to retrieve price data.
Glock-18 | Bunsen Burner (Field-Tested)
Glock-18%20%7C%20Bunsen%20Burner%20%28Field-Tested%29
Unable to retrieve price data.

如果我在我的浏览器中转到http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Tec-9%20%7C%20Isaac%20%28Field-Tested%29(例如)它似乎加载正常。

有什么想法吗?

0 个答案:

没有答案