/ Published in: PHP
Expand |
Embed | Plain Text
function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; }
Comments
Subscribe to comments
You need to login to post a comment.

PHP provide other two method to fetch an URL - Curl and Fsockopen. http://www.bin-co.com/php/scripts/load/
TY :)
A slight evolved version with some defaults and basic error handling:
function filegetcontentscurl($url, $curlopt = array()){ $ch = curlinit(); $defaultcurlopt = array( CURLOPTTIMEOUT => 2, CURLOPTRETURNTRANSFER => 1, CURLOPTFOLLOWLOCATION => 1, CURLOPTUSERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 AlexaToolbar/alxf-1.54 Firefox/3.6.13 GTB7.1" ); $curlopt = array(CURLOPTURL => $url) + $curlopt + $defaultcurlopt; curlsetoptarray($ch, $curlopt); $response = curlexec($ch); if($response === false) triggererror(curlerror($ch)); curl_close($ch); return $response; }
Oops, didn't know cant post code! Here's the link - http://snipplr.com/view/51161/basic-curl-wrapper-function-for-php/