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