取代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 }

 

posted @ 2015-04-13 22:26  敲着键盘看风景  阅读(330)  评论(0编辑  收藏  举报