我currentley试图从网站获取数据,并在我的PHP脚本中使用它。如何在URL中使用file_get_contents()和非ASCII字符?
我想达到的联系是: http://steamcommunity.com/market/priceoverview/?country=US¤cy=3&appid=730&market_hash_name=★%20Bayonet
这里是我的代码:
<?php
$skin = $_GET['market_hash_name'];
$link = "http://steamcommunity.com/market/priceoverview/?country=US¤cy=3&appid=730&market_hash_name=".$skin."";
$FN = file_get_contents($link);
echo $FN;
?>
这就是我如何使用我的链接:
http://myhost.com/getPrice.php?market_hash_name=★ Bayonet
这是我得到的错误:
警告:file_get_contents(http://steamcommunity.com/market/priceoverview/?country=US¤cy=3&appid=730&market_hash_name =★卡口):无法打开流:HTTP请求失败! HTTP/1.0 500 F中内部服务器错误:\ XAMPP \ htdocs中\ getPrice.php第5行
编辑:
好了,我已经找到了我的问题的解决方案,但现在一个新的错误正在上传:
Warning:file_get_contents(http://steamcommunity.com/market/priceoverview/?country=US¤cy=3&appid=730&market_hash_name=%E2%98%85+Bayonet+%7C+Stained(Factory New)):无法打开流:HTTP请求失败! HTTP/1.0 500 F中内部服务器错误:\ XAMPP \ htdocs中\ getPrice.php线路7
这是我如何用我现在的链接:
getPrice.php market_hash_name =★刺刀|彩绘
这是我的代码:
function getPrice($string) {
$skin = urlencode($_GET['market_hash_name']);
$link = "http://steamcommunity.com/market/priceoverview/?country=US¤cy=3&appid=730&market_hash_name=".$skin." ".$string;
$content = file_get_contents($link);
$data = json_decode($content, true);
return $data['lowest_price'];
}
$FN = getPrice("(Factory New)");
$MW = getPrice("(Minimal Wear)");
$FT = getPrice("(Field-Tested)");
$WW = getPrice("(Well-Worn)");
$BS = getPrice("(Battle-Scarred)");
echo "Factory New: $FN; Minimal Wear: $MW; Field-Tested: $FT; Well-Worn: $WW; Battle-Scared: $BS";
'HTTP://steamcommunity.com/market/priceoverview/国家= US&货币= 3的appid = 730&market_hash_name =%E2%98%85%20Bayonet' – Steve 2014-09-26 15:45:30
尝试设置的unicodecaractère而不是复制/粘贴这样的天气caractère:★ – 2014-09-26 15:47:19
根据你的编辑,你需要使用Curl。 – 2014-09-26 16:05:57