public function curl_get($url,$string="",$type="get",$res="arr"){
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$url);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串不输出到屏幕上
if(strtolower($type)=="post"){
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
}
$data = curl_exec($ch);//运行curl
curl_close($ch);
if(curl_errno($ch)){
return curl_error($ch);
}else{
if($res=='arr'){
return json_decode($data,true);
}elseif ($res=='obj') {
return json_decode($data);
}else{
return $data;
}
}
}
$tring为地址栏一样的传参