How PHP captures webpage content

Source: Internet
Author: User
PHP captures page content in actual development, such as a simple content collector, extracting part of the content in the web page, etc, the captured content is filtered by using a regular expression to obtain the desired content. for how to use a regular expression to filter, here... PHP captures page content in actual development, such as a simple content collector, extracting part of the content in the web page, etc, the captured content is filtered through the regular expression to get the content you want. As for how to use the regular expression to filter, we will not introduce it here, the following are several common methods to capture webpage content using php.

1. file_get_contents,The PHP code is as follows:

 

2. curl,The PHP code is as follows:

 

3. fopen-> fread-> fclose,The PHP code is as follows:

 

Note:

1. use file_get_contents and fopen to enable allow_url_fopen. Method: edit php. ini and set allow_url_fopen = On. when allow_url_fopen is disabled, neither fopen nor file_get_contents can open remote files.

2. use curl to enable curl. Method: modify php. ini in windows, remove the semicolon before extension = php_curl.dll, and copy ssleay32.dll and libeay32.dll to C: WINDOWSsystem32. install curl extension in Linux.

Method 1: install cURL

wget http://curl.haxx.se/download/curl-7.17.1.tar.gz tar -zxf curl-7.17.1.tar.gz ./configure --prefix=/usr/local/curl make & make install

To install php, you only need to turn on the switch -- with-curl =/usr/local/curl. this extension library is still very good and is an effective alternative to fsockopen and so on.

Method 2: Go to the source code directory for installing the original php.

cd extcd curlphpize./configure --with-curl=DIRmake & make install

The curl. so file will be generated under PHPDIR/ext/curl/moudles/, copy the curl. so file to the configuration directory of extensions, and modify php. ini.

Extension = curl. so

The first method tried N times and failed all the time, so I gave up and used the second method for installation. phpize prompts that the installation could not be found, in fact, the command is in the/usr/local/php/bin/target:

#/Usr/local/php/bin/phpize

./Configure -- with-curl = DIR you must specify the php configuration path as follows:

#./Configure -- with-php-config =/usr/local/php/bin/php-config -- with-curl = DIR

Note:In the above information, the -- with-php-config is written as -- with-php-config, and then compiled and installed:

# Make

# Make install

Here will prompt the path to generate the file curl. so:/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

Go to this path and copy the curl to the extension_dir Directory (you can view phpinfo in the local directory but directly see php.int ).

Modify php. ini

extension=curl.so# /usr/local/php/bin/php -m

If a curl entry is displayed, the operation is successful.

Restart apache

# /usr/local/apache2/bin/apachectl stop# /usr/local/apache2/bin/apachectl start

The CURL entry is displayed in phpinfo.

Article address:

Reprint at will ^ please include the address of this 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.