0

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

2 Answers 2

1

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

0

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

1
  • I've tried this and it still gives & in the URL that it tries to get. I edited my post to show my code where I attempt to get the file Sep 9, 2013 at 15:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.