Simple PHP Curl Example: Download an URL

To work with websites, both for posting and getting data, CURL is the best option. Curl library is available for almost all languages like C/C++, Java, PHP. To start working with curl, you must install php-curl

Once installed, you can take a look at this simple example.


function downloadURL($URL) {
 if(!function_exists('curl_init')) {
 die ("Curl PHP package not installedn");

 /*Initializing CURL*/
 $curlHandle = curl_init();

 /*The URL to be downloaded is set*/
 curl_setopt($curlHandle, CURLOPT_URL, $URL);

 /*Now execute the CURL, download the URL specified*/
 $response = curl_exec($curlHandle);
 return $response;

echo downloadURL("");

Specify any parameter (URL of a webpage) for the function downloadURL. See the output of the script on the browser or the console. You can see the HTML source code of the webpage

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s