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.


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:


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


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: Gecko/20080311 Firefox/');
$data = curl_exec($ch);

$xml = simplexml_load_string($data);

the api requires an user agent to be specified


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

  • 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 Commented 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.