Php remote document collection-PHP source code

Source: Internet
Author: User
Php collects remote articles and jumps to the simple class

Db = $ db;} function geturlfile ($ url) {$ url = trim ($ url); $ content = ''; if (extension_loaded ('curl ')) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt ($ ch, CURLOPT_HEADER, 0); $ content = curl_exec ($ ch); curl_close ($ ch);} else {$ content = file_get_contents ($ url );} return trim ($ content) ;} Function get_all_url ($ code) {preg_match_all ('/"\'] +) [" | \ ']? \ S * [^>] *> ([^>] +)/is ', $ code, $ arr ); return array ('name' => $ arr [2], 'URL' => $ arr [1]);} function get_sub_content ($ str, $ start, $ end) {$ start = trim ($ start); $ end = trim ($ end); if ($ start = ''| $ end = '') {return $ str ;}$ str = explode ($ start, $ str); $ str = explode ($ end, $ str [1]); return $ str [0];} function vd ($ var) {echo "\ r \ n"; echo "\ r \ n"; var_dump ($ var ); echo "\ r \ n"; echo "" ;}}?> Geturlfile ($ url); // defines the collection list range $ start = ''; $ end = ''; // Obtain the article URL and TITLE $ code = $ gather-> get_sub_content ($ html, $ start, $ end) in the interval ); $ newsAry = $ gather-> get_all_url ($ code); // print the result // $ gather-> vd ($ newsAry ); $ tarGetUrl = $ newsAry ['URL'] [0]; // Obtain the target url HTML $ html = $ gather-> geturlfile ($ tarGetUrl ); // define the collection list range $ start = ''; $ end =''; // Obtain the article URL and TITLE $ code = $ gather-> get_sub_content ($ html, $ start, $ end); $ killHtml = ''; $ kill Html2 = ''; $ code = str_replace ($ killHtml," ", $ code); $ code = str_replace ($ killHtml2," ", $ code ); $ gather-> vd ($ code);?>

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.