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

Source: Internet
Author: User
PHP-based simple collection data warehouse receiving program [continued], php collection warehouse receiving sequel. PHP-based simple collection data warehouse receiving program [continued], php collection warehouse receiving sequent in the previous article, we have collected the list data on the news information page, the next step is to [continue] the PHP-based simple data collection and warehouse receiving program, and the php collection and warehouse receiving procedure

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>/iUs "; preg_match ($ pattern, $ content, $ info); // obtain the information to store info echo $ title = $ row [1]."
"; Echo $ content = $ info [0]." "; // Insert database $ add =" insert into content (title, content) value ('$ title',' $ content') "; mysql_query ($ add ); $ sql2 = "select * from list where id> $ id order by id asc limit 1"; $ result2 = mysql_query ($ sql2); $ row2 = mysql_fetch_array ($ result2 ); // obtain the corresponding url address if ($ row2 ['id']) {echo "script window. location = 'content. php? Id = $ row2 [0] 'script ";}?>

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!

In the previous article, we have collected the list data on the news page. The next step is to do the following...

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.