Dedicate a packaged curl function for easy invocation (grab data dedicated) _php tutorial

Source: Internet
Author: User
Dedicate a encapsulated curl function for easy invocation

Copy CodeThe code is as follows:
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;
}


Grab data dedicated

http://www.bkjia.com/PHPjc/328110.html www.bkjia.com true http://www.bkjia.com/PHPjc/328110.html techarticle dedicate a encapsulated curl function to make it easy to invoke the copy code code as follows: Function curl ($url, $ifpost = 0, $datafields = ", $cookiefile =", $v = False) {$hea Der = Array ("Conn ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.