PHP curl_init function Usage _php Tutorial

Source: Internet
Author: User
Using the PHP Curl Library, you can easily and effectively grab pages. You just need to run a script, then analyze the page you crawled, and then you can get the data you want in a program.

Whether you want to take part of the data from a link, or take an XML file and import it into the database, the fear is simply to get the Web content, CURL is a powerful PHP library. The Curl Library in PHP (Client URL library function) curl_close-close a Curl session curl_copy_handle-copy all the contents and parameters of a Curl connection resource curl_errno- Returns a numeric number containing the current session error information curl_error-returns a string containing the current session error information curl_exec-performs a curl session curl_getinfo-gets information about a Curl connection resource handle curl_init- Initializes a Curl session curl_multi_add_handle-adds a separate curl handle resource to the Curl batch session curl_multi_close-closes a batch handle resource curl_multi_exec- Parses a curl batch handle curl_multi_getcontent-returns the text stream of the obtained output curl_multi_info_read-gets the associated transport information for the currently resolved Curl curl_multi_init- Initializes a curl batch handle resource curl_multi_remove_handle-removes a handle resource from the Curl batch handle resource Curl_multi_select-get all the sockets associated with The curl extension, which can then be "selected" curl_setopt_array-set session parameters for a curl as an array curl_setopt-set session parameters for a Curl Curl_ve rsion-Get Curl Related version information The function of the Curl_init () function Initializes a curl session, and the only parameter of the Curl_init () function is optional, which represents a URL address. The function of the curl_exec () function is to perform a curl session, and the only argument is the handle returned by the Curl_init () function. The function of the Curl_close () function is to close a curl session, and the only argument is the handle returned by the Curl_init () function. Example one: basic example basic example code is as follows: Example two: Post Data sendsms.php, which can accept two form fields, one is the phone number, one is the text message content. The post data code is as follows: Example three: Using a proxy server with Proxy server code is as follows: Example four: Simulation login Curl Simulation Login Discuz program, suitable for DZ7.0, will username change to your user name, Userpass changed to your password on it. The Curl emulation login discuz Program copy Code code is as follows: /I ', $contents, $matches); if (!empty ($matches)) {$formhash = $matches [1];} else {die (' not found the Forumhash ');}//post data, get cookie $cookie _file = DirName (__file__). '/cookie.txt '; $cookie _file = Tempnam ('/tmp '); $ch = Curl_init ($login _url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_postfields, $post _fields); curl_setopt ($ch, Curlopt_cookiejar, $cookie _file); Curl_exec ($ch); Curl_close ($ch); Take the cookie above to get the page content you need to log in to see $ch = Curl_init ($get _url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 0); curl_setopt ($ch, Curlopt_cookiefile, $cookie _file); $contents = curl_exec ($ch); Curl_close ($ch); Var_dump ($contents);

http://www.bkjia.com/PHPjc/730221.html www.bkjia.com true http://www.bkjia.com/PHPjc/730221.html techarticle using the PHP Curl Library, you can easily and effectively grab pages. You just need to run a script, then analyze the page you crawled, then you can get what you want in a program ...

  • 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.