: API demands & and not & So I recently changed where my site is hosted, and my yp.com API requests are being thrown off, perhaps by a new version of PHP. http://api2.yp.com/listings/v1/search?searchLoc=oklahoma%20ok&te
So I recently changed where my site is hosted, and my yp.com API requests are being thrown off, perhaps by a new version of PHP.
api2.yp.com/listings/v1/search?searchLoc=oklahoma%20ok&term=Plumbing&format=xml&key=xxxx&sort=name&listingcount=50&pagenum=1
works great, even just by typing it into the URL.
But now in my PHP script, when I build the URL it automatically changes all & into &.
So if I type:
api.com/bla?var1=xxx&var2=yyy
even in the browser I get errors.
So I need for PHP to not change this in the URL, or I can't talk to the API I'm using.
I've looked all over the stacks for this and found similar questions but no resuts.
Here's my code
$apiURL = "http://api2.yp.com/listings/v1/search?searchLoc=oklahoma%20ok&term=Plumbing&format=xml&key=xxx&sort=name&listingcount=50&pagenum=1";
file_get_contents($apiURL);
More posts by @Jessie594
2 Comments
Sorted by latest first Latest Oldest Best
Solution posted by the question-asker in the question
I ended up just using curl, which doesn't seem to encode
$apiURL = "http://api2.yp.com/listings/v1/search?searchloc=".$searchLoc."&term=".$category."&format=xml&key=".$key."&sort=name&pagenum=".$pageNumber;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$apiURL);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$data = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($data);
the api requires an user agent to be specified
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.