How to store captured web pages to the mysql database

Source: Internet
Author: User
How to save the captured webpage to a PHP code (test. php) written in the mysql database: & lt ;? Php? $ Url = & quot; http://www.baidu.com/&quot ;;? $ Contents = file_get_contents (how to save the web page captured by $ u to the mysql database
Write a PHP code (test. php ):

$ Url = "http://www.baidu.com /";?
$ Contents = file_get_contents ($ url );?
Echo $ contents;?>?

How can I capture the webpage data in the mysql database? The table is Page field 1: Pageid | field 2: Pagetext


Code

------ Solution --------------------
Is insert?
All values are available, and fields are also available...
------ Solution --------------------
If pageid is auto-incrementing. Yes.


$ SQL = "insert into 'page' values ('', '$ contents ')";
------ Solution --------------------
Preg_match_all ('/(.*?) <\/Table>/is ', $ str, $ match); // replace str with your own string.
Print_r ($ match );
------ Solution --------------------
PHP code
$ Contents = file_get_contents ('A. php '); preg_match_all ('/()/iUs ', $ contents, $ match ); // if there are multiple results to be matched, output the match array to be organized into a string... $ contents = $ match [1] [0]; mysql_connect ('localhost', 'root', ''); mysql_select_db (" lookdb "); mysql_query ("set names 'gbk'"); $ SQL = "insert into page (pagetext) VALUES ('{$ contents}')"; mysql_query ($ SQL );

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.