March 26, 2007

Reading site content using CURL

For reading content of a website in PHP, there are lot of different ways & functions available like:
$site_content=file($url); #OR
$site_content=file_get_contents($url) ;

But these functions does not work in some server environments where "allow_url_fopen" is off in php.ini & you don't have permission to change this.
You can use the following alternative (using CURL) in that case.

$url="http://www.bestenough.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
curl_close ($ch);
echo($store);