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

yipeiwu_com5年前PHP代码库
奉献出一个封装的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;
}


抓数据专用

相关文章

php中批量替换文件名的实现代码

代码如下 复制代码 代码如下: $dir = 'D:\Program Files\resource\application\Skin\PNG\\';//注意这里的路径,最后要加两个\,第...

解决file_get_contents无法请求https连接的方法

错误: Warning: fopen() [function.fopen]: Unable to find the wrapper "https" - did you forget to...

ajax 的post方法实例(带循环)

ajax 的post方法实例(带循环)

用上循环就是为了在数据发送前进行合理的处理,解决在脚本语言对数据进行另外需求处理时出现的超时现象。处于对ajax认识未深,如有说得不对或不到位的,还请指教。     ajax中的po...

10款PHP开源商城系统汇总介绍

  在当今经济危机的大环境下,网上购物越来越来吃香,网上开店成本低,快捷方便,出名的电子商务网站有淘宝,拍拍,Ebay或是最新的百度有啊,这些网站都提供开店的机会,如果是想自己搭建购物平...

PHP5常用函数列表(分享)

如下所示:复制代码 代码如下:  usleep() 函数延迟代码执行若干微秒。  unpack() 函数从二进制字符串对数据进行解包。  uniqid() 函数基于以微秒计的当前时间,生...