获取此错误
[Tue Aug 18 14:41:57.614006 2015] [:error] [pid 21389] [client 67.90.138.68:5794] PHP警告:file_get_contents(http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=BR:Vigilante Crate):无法打开流: HTTP请求失败! HTTP / 1.0 500内部服务器错误\ r \ n
<?php
foreach($json2['rgDescriptions'] as $i){
$item = $i['market_name'];
$icon = $i['icon_url'];
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . $item;
$grab = file_get_contents($fetchdata);
$id = json_decode($grab, true);
echo '<img src="'. $imgurlbase . $icon . '/64fx64f">' . '<a class="btn btn-primary btn-lg" href="#" role="button">' . $item . '</a>'. '<a class="btn btn-primary btn-lg" href="#" role="button">'. $id['lowest_price'].'</a>'.'<br>';
}
出于某种原因&amp;在基本网址中传递的是&#39;&amp;安培;&#39;每次都在网址中而不是&amp;
我不是最好的PHP,但我正在寻找的任何东西都没有提出原因。它与json_decode有关吗?这是我唯一的猜测。
答案 0 :(得分:2)
你需要对字符串进行编码:
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . urlencode($item);
适合我:
php > $fetchdata ='http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name='.urlencode('BR: Vigilante Crate');
php > $grab = file_get_contents($fetchdata);
php > print_r(json_decode($grab));
stdClass Object
(
[success] => 1
[lowest_price] => $0.07
[volume] => 4,994
[median_price] => $0.07
)