奉献出一个封装的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的简单跳转提示的实现详解

PHP的简单跳转提示的实现详解

在PHP开发中,尤其是MVC框架或者项目中,会碰到很多跳转情况,比如:登录成功或失败后的跳转等等。 以下以MVC框架开发中为基础,示例讲解: 在基础控制器类中:Conrtoller.cl...

php小技巧 把数组的键和值交换形成了新的数组,查找值取得键

复制代码 代码如下: $cityname = array_flip($city_DB[name]); //把数组的键和值交换形成了新的数组 $city_name = array_sear...

php牛逼的面试题分享

1.nginx使用哪种网络协议? nginx是应用层 我觉得从下往上的话 传输层用的是tcp/ip 应用层用的是http fastcgi负责调度进程 2. <? echo 'hel...

解析php中用PHPMailer来发送邮件的示例(126.com的例子)

<?phprequire_once('../class.phpmailer.php');$mail= new PHPMailer();$body= "我终于发送邮件成功了!呵呵!g...

php文件系统处理方法小结

本文总结分析了php文件系统处理方法。分享给大家供大家参考,具体如下: 文件类型 以Linux为模型的, 在Windows只能获取file, dir或unknow 三种类型 在Linux...