Mobile app version of vmapp.org
Login or Join
Jessie594

: 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

@Jessie594

Posted in: #Api #Php #Url

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);

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Jessie594

2 Comments

Sorted by latest first Latest Oldest Best

 

@Kristi941

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

10% popularity Vote Up Vote Down


 

@Kevin317

Look into using html_entity_decode() to convert & back into &.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme