函数
//curl v function curl_v($url, $gzip = false, $timeout = 10) { $ch = curl_init(); if($gzip){ curl_setopt($ch,CURLOPT_ENCODING ,'gzip'); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); $contents = trim(curl_exec($ch)); curl_close($ch); return $contents; }
使用
抓取百度首页的HTML代码
$code = curl_v('http://www.baidu.com/'); dump($code);
输出