The reason analysis of the failure of grasping content in file_get_contents function _php Tutorial

Source: Internet
Author: User
Using file_get_contents to crawl the content of the page is not successful, perhaps because some host services to the PHP allow_url_fopen option is closed, is unable to directly use file_get_contents to get the content of the remote Web page. That is, you can use another function, curl.
Here are the different ways to do the same function for file_get_contents and curl two functions
Example of using the File_get_contents function:
Copy CodeThe code is as follows:
< PHP
$file _contents = file_get_contents (' http://www.jb51.net ');
echo $file _contents;
?>

Use an example of a curl function:
Copy CodeThe code is as follows:
< PHP
$ch = Curl_init ();
$timeout = 5;
curl_setopt ($ch, Curlopt_url, ' http://www.jb51.net ');
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
$file _contents = curl_exec ($ch);
Curl_close ($ch);
echo $file _contents;
?>

http://www.bkjia.com/PHPjc/327841.html www.bkjia.com true http://www.bkjia.com/PHPjc/327841.html techarticle use file_get_contents to crawl page content is not successful, perhaps because some host service provider to PHP allow_url_fopen option is closed, is unable to directly use file_get_contents to get ...

  • Related Article

    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.