我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