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/" ;;? $ 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 );