Deep file_get_contents function Crawl content failure reason Analysis _php skill

Source: Internet
Author: User
Using file_get_contents to crawl the content of the page is not successful, probably because some host service providers put PHP allow_url_fopen option is off, it is impossible 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 file_get_contents and curl two functions
Example of using the File_get_contents function:
Copy Code code as follows:

< PHP
$file _contents = file_get_contents (' http://www.jb51.net ');
echo $file _contents;
?>

To use an example of a curl function:
Copy Code code 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;
?>

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.