Home  >  Article  >  Backend Development  >  PHP uses file_get_contents instead of using curl instance, curlgetcontents_PHP tutorial

PHP uses file_get_contents instead of using curl instance, curlgetcontents_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:14:49782browse

php uses file_get_contents instead of using curl instance, curlgetcontents

The example in this article describes the method of using file_get_contents in PHP instead of using curl. I would like to share it with you for your reference. The specific implementation method is as follows:

It is actually rare to use file_get_contents instead of curl, but sometimes when you encounter that the server does not support curl, we can use file_get_contents instead of curl. Let’s look at an example.

When you try all means to find that the server really cannot use curl. Or when curl does not support https. When curl https appears 502. When you don't want to reinstall the website environment, you can use file_get_contents instead.
curl commonly used curl get curl post
Instead of curl get, just use file_get_contents($url)
curl post replacement is as follows:

Copy code The 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 be helpful to everyone’s PHP programming design.

php cannot obtain content using file_get_contents or curl

Simulate a header information
array( 'method'=>"GET", 'header'=>"User-Agent: " .$_SERVER['HTTP_USER_AGENT']."\r\n" ) ); $context = stream_context_create($opts); $url = dynamic.12306.cn/...0$data = file_get_contents($url,null, $context);echo $data;?> That’s it

Use PHP's file_get_contents or curl (expose) and echo (display)

Purely automatic entry, or manual entry with manual help. It would be much easier if done manually. It is nothing more than writing a regular expression to get the URL and title of the page

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

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

Make a POST request, and then intercept the corresponding needs from the page. When you want to access the second version, send

as a GET request. At this time, you need to send parameters to the bar in the same way until the tenth page. There are

similar reptiles on the PHP pipe network, go to the next one, it is very convenient

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/907835.htmlTechArticlephp uses file_get_contents instead of using curl examples, curlgetcontents This article describes how php uses file_get_contents instead of using curl, share it with For your reference. Specific actual...
Statement:
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