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'];   
3
  • Share your php code as well Commented Feb 14, 2016 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. Commented Feb 14, 2016 at 13:52
  • $priceURL = 'steamcommunity.com/market/priceoverview/… '; $priceString = file_get_contents($priceURL); $price_json = json_encode($priceString, true); echo $price_json['lowest_price']; Commented Feb 14, 2016 at 13:55

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

5 Comments

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. It seems your url is wrong try with browser directly
I think its the right url.. (steamcommunity.com/market/priceoverview/…) You can try and open it
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.