2

I have a problem i am trying to use

    file_get_contents('');

to request the contents of a url but php keeps adding

    amp;

to every part of the url that has an & symbol te url I am trying to request is like the one bellow

    http:site.com/api/user.php?id=1&gender=male&tag=coolman

Now if I load this url in a browser my self it works perfect and I can see the content but wen i try grab the content in php using the function above it trys to load the url like bellow

    http:site.com/api/user.php?id=&gender=&tag=

and because it has added the amp; the request fails every single time dose anyone know why this is and how I can stop it please ?

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
saveonsky
  • 51
  • 3

1 Answers1

-1

In this case you can use htmlspecialchars_decode()

<?php

$url = "http://example.com/api/user.php?id=&amp;gender=&amp;tag=coolman";
$url = htmlspecialchars_decode($url);

$content = file_get_contents($url);

?>

Read more at:

http://php.net/manual/en/function.htmlspecialchars-decode.php

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63