Search code examples
phphttpweb-services

URL call in PHP


I'm using an API in PHP. I have to push datas into this API. For example, if I go to http://www.api.com/api.php?data=mydata , I push "mydata" to the API.

In fact I want to use PHP instead of typing that data in URL bar (that could be very nice haha)


Solution

  • Does this do want you need?

    $URL = "http://www.api.com/api.php?data=mydata";
    $data = file_get_contents($URL);
    

    data now contains the response.