Home >Backend Development >PHP Tutorial >Program PHP Collection Program Principle Analysis
After thinking hard for a few days, I finally figured out the reason behind it. Write it down here and ask experts to correct me.
The idea of the collection program is very simple. It is nothing more than opening a page, usually a list page, getting the addresses of all the links in it, and then opening the links one by one to look for what we are interested in. If found, put it into the database or elsewhere. processing. Let's talk about it with a very simple example.
First determine a collection page, usually the list page. The target here is: http://www.jb51.net/article/11/index.htm. This is a list page, and our purpose is to collect all articles on this list page.
There is a list page. The first step is to open it and incorporate its content into our program. Generally, the two functions fopen or file_get_contents are used. We use fopen as an example here. How to open it? It's very simple: $source=fopen("http://www.jb51.net/article/11/index.htm",'r'); In fact, the content has been incorporated into our program. Note that the $source obtained is a resource, not a processable text, so the function fread is used to read the content into a variable. This time it is a real editable text. Example:
$c//www.jb51.net/article/7/all/545.1.htm)]. By looking at the source code, we can see that the link addresses of the articles inside all look like this
The above is an introduction to the program PHP collection program principle analysis, including program content. I hope it will be helpful to friends who are interested in PHP tutorials.