Php uses fopen to implement a simple web page collection program

Source: Internet
Author: User
This collection program is a very simple program. I personally think it is not suitable for collecting a large number of data on a single page, because the fopen function is not ideal for remote file operations and multithreading, this is just a combination of the author's experience. the code is as follows... this collection program is a very simple program. I personally think it is not suitable for collecting a large number of data on a single page, the fopen function is not ideal for remote file operations and multithreading. this is just a combination of the codes written by an author who thinks it is fun. the code is as follows:

 Utf8_iconv ($ content ):";} /* get all matched content * @ param string $ str content * @ param string $ start match * @ param string $ end abort match * @ return array */private function utf8_iconv ($ content) {return iconv ('gbk', 'utf-8', $ content);} private function strCutAll ($ str, $ start, $ end) {$ content = explode ($ start, $ str); $ matchs = array (); $ sum = count ($ content); for ($ I = 1; $ I <$ sum; $ I ++) {$ tmp = explode ($ end, $ content [$ I ]); $ Matchs [] = $ tmp [0]; unset ($ tmp);} return $ matchs ;} /* obtain the first matched content * @ param string $ str content * @ param string $ start match * @ param string $ end abort match * @ return string */private function strCut ($ str, $ start, $ end) {$ content = strstr ($ str, $ start); $ content = substr ($ content, strlen ($ start), strpos ($ content, $ end)-strlen ($ start); return $ content ;}?>
/* Collection program */header ("content-Type: text/html; charset = utf-8 "); // $ nr = file_get_contents ('/webback/php-yi-ju-hua-hou-men-zhuan '); $ nr = $ this-> fetchbyurl ('/webback/php-yi-ju-hua-hou-men-zhuan'); // recommended, you can also use curl dump ($ this-> strCut ($ nr ,'

','

'); // Get the content. You need to further filter (preg_match_all) dump ($ this-> strCutAll ($ nr ,'',''); Get the title

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.