PHP uses CURL to download remote HTML files

Source: Internet
Author: User
PHP uses CURL to download remote HTML files
It is said that Curl is more efficient than file_get_contents in downloading remote HTML files.




  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. // Return the information obtained by curl_exec () in the form of a file stream instead of directly outputting it. If no echo is added, the output is automatically generated even if no echo exists.
  8. $ Content = curl_exec ($ ch );
  9. // Execute
  10. Curl_close ($ ch );
  11. // Close
  12. Echo $ content;

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.