Php uses file_get_contents instead of curl instance, curlgetcontents

Source: Internet
Author: User

Php uses file_get_contents instead of curl instance, curlgetcontents

This example describes how php uses file_get_contents instead of curl. The specific implementation method is as follows:

File_get_contents is rarely used to replace curl, but sometimes you can use file_get_contents instead of curl when the server does not support curl. The following is an example.

When all methods are used to find that the server really cannot use curl. Or curl does not support https. When curl https is 502. If you do not want to reinstall the website environment, use file_get_contents instead.
Curl get curl post, which is frequently used by curl
Use file_get_contents ($ url) instead of curl get.
Curl post is replaced by the following:

Copy codeThe Code is as follows: function Post ($ url, $ post = null ){
$ Content = http_build_query ($ post );
$ Content_length = strlen ($ content );
$ Options = array (
'Http' => array (
'Method' => 'post ',
'Header' => "Content-type: application/x-www-form-urlencoded ",
'Content' => $ post
)
);
Return file_get_contents ($ url, false, stream_context_create ($ options ));
}

I hope this article will help you with php programming.


Neither file_get_contents nor curl can be used in php to obtain content.

Simulate header information
<? Php $ opts = array ('http' => array ('method' => "GET", 'header' => "User-Agent :". $ _ SERVER ['HTTP _ USER_AGENT ']. "\ r \ n"); $ context = stream_context_create ($ opts); $ url = dynamic.12306.cn/.20.1_data = file_get_contents ($ url, null, $ context); echo $ data;?> In this way, you can

 
Use file_get_contents or curl (proposal) and echo (Display) of php)

Automatic Input only, or manually entered by the partner. It would be much easier to manually write a regular expression to put the page

Url and title. If it is purely automatic, you must write a program to simulate your normal access.

When you reach the first page, it is a POST request sent, you need to send the corresponding parameters

And POST request, and then the page captures the corresponding needs, when you want to access the second version, send

The request is a GET request. In this case, the parameter must be sent in the past until the tenth page. Php manager available on the Internet

Similar crawler, It is very convenient to go to the next one

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.