PHP json url未正确传递替换&;与&;amp;

PHP json url未正确传递替换&;与&;amp;,php,json,Php,Json,获取此错误 [8月18日星期二14:41:57.614006 2015][:错误][pid 21389][client 67.90.138.68:5794]PHP警告:文件获取内容(:私刑板条箱):无法打开流:HTTP请求失败!HTTP/1.0 500内部服务器错误\r\n <?php foreach($json2['rgDescriptions'] as $i){ $item = $i['market_name']; $icon = $i['icon_url']; $fetchdata

获取此错误

[8月18日星期二14:41:57.614006 2015][:错误][pid 21389][client 67.90.138.68:5794]PHP警告:文件获取内容(:私刑板条箱):无法打开流: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&currency=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>';
}

您需要对字符串进行编码:

$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110&currency=1&market_hash_name=' . urlencode($item);
为我工作:

php > $fetchdata ='http://steamcommunity.com/market/priceoverview/?appid=295110&currency=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
)

唉,我只关注url,而不是项目变量。谢谢你!没问题,很高兴它能工作:)当然,您可能应该使用类似的方法来安全地构建URL,但是对于像您这样的简单用例,这几乎不值得