1

How do I stop the browser adding amp; on every & there is in the URL?

So I am trying to get a JSON file from a URL

(http://steamcommunity.com/market/priceoverview/?currency=1&appid=570&market_hash_name=Inscribed%20Blades%20of%20Voth%20Domosh).

However, it keeps on adding amp; on every & there is, which makes the JSON returns null.

URL becomes: (http://steamcommunity.com/market/priceoverview/?currency=1&appid=570&market_hash_name=Inscribed%20Blades%20of%20Voth%20Domosh

Can anyone help me to stop my php doing this all the time?

Here is my code:

$priceURL = 'http://steamcommunity.com/market/priceoverview/?currency=1&appid=570&market_hash_name=Genuine%20Bloodfeather%20Wings   ';

                                        $priceString = file_get_contents($priceURL);
                                        $price_json = json_encode($priceString, true);
                                        echo $price_json['lowest_price'];   
KMackinley
  • 347
  • 1
  • 3
  • 8
  • Share your php code as well – Niklesh Raut Feb 14 '16 at 13:50
  • This is the correct behaviour, if a "&" should be sent as text. Otherwise it would be taken as a delimiter between parameters of the query part of the request (_...?par1=val1&par2=val2_). On the server side, in a php script, you could decode it (_$par = decode_url($_GET['par1'])_) before using it. – hherger Feb 14 '16 at 13:52
  • $priceURL = 'http://steamcommunity.com/market/priceoverview/?currency=1&appid=570&market_hash_name=Genuine%20Bloodfeather%20Wings '; $priceString = file_get_contents($priceURL); $price_json = json_encode($priceString, true); echo $price_json['lowest_price']; – KMackinley Feb 14 '16 at 13:55

1 Answers1

0

You should decode url, use like this.

  $priceURL = 'http://steamcommunity.com/market/priceoverview/?currency=1&appid=570&market_hash_name=Genuine%20Bloodfeather%20Wings   ';

 $priceURL =  urldecode($priceURL);
Niklesh Raut
  • 29,238
  • 9
  • 61
  • 94
  • I am using file_get_contents and json_decode. After using what you told me to, i got this error "file_get_contents(): php_network_getaddresses: getaddrinfo failed: No such host is known. " – KMackinley Feb 14 '16 at 14:03
  • @KMackinley. It seems your url is wrong try with browser directly – Niklesh Raut Feb 14 '16 at 14:30
  • I think its the right url.. (http://steamcommunity.com/market/priceoverview/?currency=1&appid=570&market_hash_name=Genuine%20Bloodfeather%20Wings) You can try and open it – KMackinley Feb 14 '16 at 14:32
  • You are doing wrong. You need to use php curl or js ajax to get api response. file_get_contents will not return php executed reponse. Onlt textual like html will return. – Niklesh Raut Feb 14 '16 at 14:52
  • Check this http://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code – Niklesh Raut Feb 14 '16 at 14:56