file_get_contents采集获取不到内容时用curl解决

public function getContent($url, $method = 'GET', $postData = array()) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20120829 Firefox/3.5.2 GTB5');
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_REFERER, $url);
$content = curl_exec($curl);

$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($httpCode == 200) {
//$content = mb_convert_encoding($content, "UTF-8", "GBK");
}
return $content;

}

posted on 2013-11-13 16:22  阿牛的哥  阅读(324)  评论(0编辑  收藏  举报

导航