取代file_get_contents 的一个采集函数
1 function url_get_content($url=''){ 2 $ch = curl_init(); 3 $timeout = 100; 4 $browser = 'Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0'; 5 curl_setopt($ch, CURLOPT_USERAGENT, $browser); 6 curl_setopt($ch, CURLOPT_URL, $url); 7 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 8 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 9 curl_setopt($ch, CURLOPT_ENCODING, ""); 10 $contents = curl_exec($ch); 11 // var_dump($contents); 12 curl_close($ch); 13 return $contents; 14 }