我目前正在寫東西,使用蒸汽網絡API,我試圖通過網絡API來獲取蒸汽市場價格像這樣:如何在PHP中跳過這些&符號?
$url = 'http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name='.$itemInfo['market_hash_name'];
的$itemInfo['market_hash_name']
是從另一個JSON我從得到的東西API。
應該返回是這樣的:
http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=SCAR-20 | Contractor (Well-Worn)
和它,這是很好的,因爲當我扔東西到瀏覽器,把它翻譯成
http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=SCAR-20%20|%20Contractor%20(Well-Worn)
返回的JSON我需要。
但是,當它與get_file_contents
使用的一些原因,它將類似於在與號這樣:
http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=Operation Breakout Weapon Case
,如果我把它變成一個瀏覽器窗口,它沒有返回值。因此,如果我使用htmlspecialchars
或html_entity_decode
並不重要,因爲無論何時我將它放入get_file_contents
,它都會再次對連字符進行編碼。
我該怎麼做?
當你看到'http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=SCAR-20%20|%20Contractor%20(Well-Worn) '你在瀏覽器中查看源代碼還是輸出? – chris85
當我運行這個,它會返回成功: 'var_dump(file_get_contents('http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=SCAR-20 | Contractor(Well-Worn)')) ;' – infomaniac