PHP function to replace file_get_contents
Jan 1st, 2009 by admin
PHP file_get_contents require allow_url_fopen to be ON in php.ini. Not a problem for hostgator since it is ON by default. But that might be dangerous (or not). Anyways, just to be safe, I turned it off in php.ini and
wrote a function to replace it using curl. I got the code from this page and added something of my own.
function file_get($site_url) {
$ch = curl_init();
$timeout = 0; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $site_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
ob_start();
curl_exec($ch);
curl_close($ch);
$file_contents = ob_get_contents();
ob_end_clean();
return $file_contents;
}

