Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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);
share|improve this question

2 Answers 2

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

share|improve this answer

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

share|improve this answer
    
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 –  Theodore Enderby Sep 9 '13 at 15:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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