取代file_get_contents 的一个采集函数

 function url_get_content($url=''){
$ch = curl_init();
$timeout = 100;
$browser = 'Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0';
curl_setopt($ch, CURLOPT_USERAGENT, $browser);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_ENCODING, "");
$contents = curl_exec($ch);
// var_dump($contents);
curl_close($ch);
return $contents;
}
上一篇:C++ IO学习


下一篇:Preface