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.
<?php
function downloadURL($URL) {
if(!function_exists('curl_init')) {
die ("Curl PHP package not installed\n");
}
/*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("http://www.mozilla.org/");
?>
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
Comments: