The difference between curl and file_get_content in PHP _php tutorial

Source: Internet
Author: User
Until recently, to do a web thief program only to find that File_get_content is completely unable to meet the demand. I think that when reading remote content, File_get_content is not as good as curl, except that it's easier to use than curl.


Main differences:

Learn to find that Curl supports a lot of protocols, FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, file, and LDAP, which means it can do a lot of things file_get_content can't. Curl in PHP can achieve remote access and acquisition of content, the implementation of PHP Web version of the FTP upload and download, to achieve the simulation of landing, interface docking (API), data transmission, implementation of analog cookies, download file breakpoints and so on, the function is very powerful.

Understanding curl Some basic use, only to find that it is not difficult, but to remember some of the settings in the parameters, difficult to get a little, but we remember a few commonly used on it.

Turn on Curl:

Because PHP does not support the Curl function by default, so if you want to use curl, you first need to open the function in php.ini, that is, to remove the extension= Php_curl.dll front of the semicolon, and then save and then restart Apache/iis.

Basic syntax:
Copy the Code code as follows:
$my _curl = Curl_init (); Initialize a Curl Object
curl_setopt ($my _curl, Curlopt_url, "http://www.jb51.net"); Set the URL you need to crawl
curl_setopt ($my _curl,curlopt_returntransfer,1); Set whether the result is saved to a string or output to a screen, 1 means that the result is saved to a string
$str = curl_exec ($curl); Execute request
Echo $str; Results of output fetching
Curl_close ($curl); Close URL Request

http://www.bkjia.com/PHPjc/768141.html www.bkjia.com true http://www.bkjia.com/PHPjc/768141.html techarticle until recently, to do a web thief program only to find that File_get_content is completely unable to meet the demand. I think, when reading the remote content, file_get_content except ...

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