Three methods for php to obtain webpage content

Source: Internet
Author: User
Three methods for php to obtain webpage content
This article introduces three methods for php to obtain webpage content. For more information, see.

The principle of using php code to obtain a webpage: capture the content and filter it by regular expressions to obtain the desired content.

The programmer home has introduced a lot about the content of regular expressions. For more information, see.

Php retrieves content, Method 1, file_get_contents

     

Php retrieves webpage content, Method 2, curl

     

Php: Method 3: fopen-> fread-> fclose

     

Note: 1. allow_url_fopen must be enabled when file_get_contents () and fopen () are used. Method: edit php. ini and set allow_url_fopen = On. when allow_url_fopen is disabled, the fopen () and file_get_contents () functions cannot open remote files.

2. when curl () is used, the curl must be enabled. Method: modify php in windows. ini, remove the semicolon before extension = php_curl.dll, and copy ssleay32.dll and libeay32.dll to C: \ WINDOWS \ system32. in Linux, install the curl extension.

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.