The difference between curl and file_get_content in php. It wasn't until recently that file_get_content was completely unable to meet the requirements when I was planning a web page thief program. In my opinion, when reading remote content, file_get_content, except for the latest website thief program, was found to be completely unable to meet the needs of file_get_content. I think file_get_content is easier to use than curl when reading remote content.
Main differences:
After learning, we found that curl supports many protocols, including FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE, and LDAP. that is to say, it can do a lot of things that file_get_content cannot do. Curl can remotely obtain and collect content in php; implement FTP upload and download in PHP web version; implement simulated login; implement interface connection (API), data transmission; implement Cookie simulation; resumable Upload of downloaded files.
After learning about the basic usage of curl, we can find that it is not difficult, but it is difficult to remember some parameters, but we can remember several common ones.
Enable curl:
Because PHP does not support the curl function by default, if you want to use curl, you must first. enable this function in ini, that is, remove the semicolon before extension = php_curl.dll, and then save it and restart apache/iis.
Basic syntax:
The code is as follows:
$ My_curl = curl_init (); // initialize 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); // you can specify whether to save the result to a string or output it to the screen. 1 indicates to save the result to a string.
$ Str = curl_exec ($ curl); // execute the request
Echo $ str; // output the captured result
Curl_close ($ curl); // closes the url request
Bytes. In my opinion, when reading remote content, file_get_content...