The difference between curl and file_get_content in PHP _php skills

Source: Internet
Author: User
Tags curl

Until recently, to do a web thief program to find that File_get_content has been completely unable to meet the demand. I think, in reading remote content, file_get_content in addition to use than curl convenient, other than curl good.


Main differences:

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

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

Open Curl:

Because PHP is not supported by default Curl function, so if you want to use curl, first need to open the function in the php.ini, that is, remove; extension= php_curl.dll before the semicolon, and then save to restart the Apache/iis is good.

Basic syntax:

Copy Code code as follows:

$my _curl = Curl_init (); Initializes a Curl object
curl_setopt ($my _curl, Curlopt_url, "http://www.jb51.net"); Set the URL you want to crawl
curl_setopt ($my _curl,curlopt_returntransfer,1); Set whether to save the result to a string or to the screen, 1 to save the result to a string
$str = curl_exec ($curl); Execute request
Echo $str; Output Crawl Results
Curl_close ($curl); Close URL Request

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.