欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

奉献出一个封装的curl函数 便于调用(抓数据专用)

程序员文章站 2022-11-14 19:30:14
奉献出一个封装的curl函数,便于调用 复制代码 代码如下: function curl($url, $ifpost = 0, $datafields = '', $coo...
奉献出一个封装的curl函数,便于调用

复制代码 代码如下:

function curl($url, $ifpost = 0, $datafields = '', $cookiefile = '', $v = false) {
$header = array("connection: keep-alive","accept: text/html, application/xhtml+xml, */*", "pragma: no-cache", "accept-language: zh-hans-cn,zh-hans;q=0.8,en-us;q=0.5,en;q=0.3","user-agent: mozilla/5.0 (compatible; msie 10.0; windows nt 6.2; wow64; trident/6.0)");
$ch = curl_init();
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, curlopt_header, $v);
curl_setopt($ch, curlopt_httpheader, $header);
$ifpost && curl_setopt($ch, curlopt_post, $ifpost);
$ifpost && curl_setopt($ch, curlopt_postfields, $datafields);
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_followlocation, true);
curl_setopt($ch, curlopt_encoding, 'gzip,deflate');
$cookiefile && curl_setopt($ch, curlopt_cookiefile, $cookiefile);
$cookiefile && curl_setopt($ch, curlopt_cookiejar, $cookiefile);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}


抓数据专用