What does php use for data collection?

(*-*)浩
Release: 2023-02-24 11:06:02
Original
2547 people have browsed it

What is collection?

is to use PHP programs to capture information from other websites into our own database and website.

What does php use for data collection?

PHP production and collection technology:

There are three methods from the bottom socket to the high-level file operation function. Implement collection.

1. Use socket technology to collect:(Recommended learning:PHP programming from entry to proficiency)

Socket collection is the lowest level. It just establishes a long connection, and then we have to construct the http protocol string ourselves to send the request.

For example, if you want to get the content of Youku page, use socket to write as follows:

Copy after login

The printed result is as follows, including the returned header information and the source code of the page:

What does php use for data collection?

2. Use curl_a set of functions

curl encapsulates the HTTP protocol into many functions. You can directly pass the corresponding parameters, which reduces the writing time. The difficulty of HTTP protocol strings.

Prerequisite: The curl extension must be enabled in php.ini.

function getHTTPS($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); curl_close($ch); return $result; } var_dump(getHTTPS($url));
Copy after login

The printed results are as follows, including only the source code of the page:

What does php use for data collection?

3. Use file_get_contents directly (the top level)

Prerequisite: Set the url address that allows opening a network in php.ini.

What does php use for data collection?

//使用file_get_contents() $data=file_get_contents("http://www.youku.com"); var_dump($data);
Copy after login

What does php use for data collection?

The above is the detailed content of What does php use for data collection?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!