Alternative For PHP file_get_contents


3/30/2009 @ 12:22 AM in Blog > Tech > Programming

My shared hosting web server doesn't like PHP's "file_get_contents" function for those nifty API calls. Specifically I was trying to do this to tinyurl or bit.ly the Twitter buttons for each post. Found a solution on the web using curl instead. Here's the direct function replacement:

function curl_file_get_contents($request){

$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $request);
$response = curl_exec($c);
curl_close($c);
return($response);
}


I lost the source of the forum I found this on, but remember it was posted by a user named "Fury". Props.