Home > Backend Development > PHP Tutorial > The difference between curl and file_get_content in php_PHP tutorial

The difference between curl and file_get_content in php_PHP tutorial

WBOY
Release: 2016-07-13 10:29:54
Original
1048 people have browsed it

Until recently, when I was trying to make a web thief program, I discovered that file_get_content could no longer meet the needs. I think that when reading remote content, except that file_get_content is more convenient to use than curl, it is not as good as curl.


Main differences:

After studying, I discovered that curl supports many protocols, including FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP. In other words, it can do many things that file_get_content cannot do. Curl can achieve remote acquisition and collection of content in PHP; implement FTP upload and download of the PHP web version; implement simulated login; implement interface docking (API), data transmission; implement simulated cookies; download file breakpoint resumption, etc., the function is very powerful .

After understanding some basic uses of curl, I found that it is not difficult. It is just a little harder to remember some of the setting parameters, but we can just remember a few commonly used ones.

Enable curl:

Because PHP does not support the curl function by default, if you want to use curl, you first need to enable this function in php.ini, that is, remove the semicolon in front of ;extension= php_curl.dll, then save and restart apache/ iis is just fine.

Basic syntax:

Copy code 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 need to crawl
curl_setopt($my_curl,CURLOPT_RETURNTRANSFER,1 ; //Output the crawled results
curl_close($curl); //Close url request


http://www.bkjia.com/PHPjc/768141.html

truehttp: //www.bkjia.com/PHPjc/768141.htmlTechArticleUntil recently, when I was trying to make a web thief program, I discovered that file_get_content could no longer meet the needs. I think that when reading remote content, file_get_content except...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template