PHP uses curl to download remote HTML files

Source: Internet
Author: User
It is said that using curl when downloading remote HTML files is a bit more efficient than file_get_contents.




  1. $ch = Curl_init ();
  2. curl_setopt ($ch, Curlopt_url, $url);
  3. Set the URL, which can be placed in the Curl_init parameter
  4. curl_setopt ($ch, Curlopt_useragent, "mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/535.1 (khtml, like Gecko) chrome/14.0.835.202 safari/535.1 ");
  5. Set UA
  6. curl_setopt ($ch, Curlopt_returntransfer, 1);
  7. The information obtained by CURL_EXEC () is returned as a file stream, rather than as a direct output. If not added, even without echo, it will automatically output
  8. $content = curl_exec ($ch);
  9. Perform
  10. Curl_close ($ch);
  11. Shut down
  12. Echo $content;
Copy Code
  • 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.