PHP-based simple collection data warehouse receiving program [continued], php collection warehouse receiving sequel

Source: Internet
Author: User

PHP-based simple collection data warehouse receiving program [continued], php collection warehouse receiving sequel

In the previous article, we have collected the list data on the news page. The next step is to read the URL to be collected from the database and capture the page.

Create a content table

However, you must note that you cannot use the incremental method of id collection URL, because IDs in the data table may be intermittent, such as id = 9, id = 11, when id = 10 is collected, the URL is blank, which may result in empty fields being collected.

One technique used here is the database query statement. When we collect the first piece of data, we can determine whether there is an id number greater than this id in the database. If so, read one, the query information already exists.

The Code is as follows:

<? Php include_once ("conn. php "); $ id = (int) $ _ GET ['id']; $ SQL =" select * from list where id = $ id "; $ result = mysql_query ($ SQL); $ row = mysql_fetch_array ($ result); // obtain the corresponding url address $ content = file_get_contents ($ row ['url']); $ pattern = "/<dd class = \" dataWrap \ "> (. *) <\/dd>/iUs "; preg_match ($ pattern, $ content, $ info); // obtain the information to store info echo $ title = $ row [1]. "<br/>"; echo $ content = $ info [0]. "

In this way, the news content we want will be collected into the database. Next we only need to sort out some data styles.


PHP collection warehouse receiving Problems

Php has the $ nr = implode ('#', $ arr) method.
However, the above is composed of "content 1 # Content 2", without the last #, if necessary
$ Nr = implode ('#', $ arr ).'#'

The stupid method is to use
Foreach ($ arr as $ vl ){
$ Nr. = $ vl ."#";
}
References: $

PHP collection warehouse receiving Problems

Mysql_connect () // connect to your database first
Mysql_select_db () // select your database
Mysql_query ("insert into your table (address, title) values ('$ tmp [1] [$ I]', $ tmp [2] [$ I])"); // OK!

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.