Get Content of URL In PHP

To Get Content from url, we use cURL library or file_get_contents method of php.Get Content of specific url is common requirement when we are using api or webservices.

Get Content of URL using cURL

We have to first check that curl support is available in our PHP environment.

 function getUrlContent($Url) {
    $cURL = curl_init(); // Initialize a cURL session
    curl_setopt($cURL, CURLOPT_URL, $Url); // URL to send request to
    curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); //return web page data
    $data = curl_exec($cURL);// Perform a cURL session
    curl_close($cURL);// cURL session
    return $data;

Now We call above function.


Get Content of URL using file_get_contents method

 $content =file_get_contents('');