PHP code for a simple PHP collector
/Is ", $ r, $ booktitle); // match the title of this page $ bookname = $ booktitle [1]; // Obtain the second layer Group $ preg = '/
/IsU '; preg_match_all ($ preg, $ r, $ zj); // connect the chapter on this page to $ bookzj = count ($ zj [1]); // calculate the number of chapter titles if ($ ver = "new") {$ content_start ="
"; $ Content_end ="
";} If ($ ver =" old ") {$ content_start =" <\/table>
"; $ Content_end ="
";} Header (" Content-Type: text/html; charset = gb2312 "); writer ($ bookname. "Total ". $ bookzj. "Section \ r \ n handsome Liu Binyu ". date ("d m j G: I: s T Y "). "Design novel collection for graduation \ r \ n ",". /ailaopo /". $ bookname. ". txt "," w + "); for ($ I = 0; $ I <$ bookzj; $ I ++) {// echo" http://book.sina.com.cn ". $ zj [1] [$ I] ". shtml "; die (); // use file_get_contents to connect the chapter to open and read the content of the opened page $ str = file_get_contents (" http://book.sina.com.cn ". $ zj [1] [$ I]. ". shtml "); preg_match ("/()(.*?) (<\/Title>)/is ", $ str, $ title); // match the title of this connection page $ title = str_replace (" _ _ Sina ", "", $ title [2]); // replace _ reading Channel _ xinlang net with null preg_match ("/(". $ content_start. ")(. *?) (". $ Content_end. ")/is", $ str, $ content); // match the content of this connection page $ content = preg_replace ("/<(. *?)> /S "," ", str_replace (" </p> "," \ r \ n ", $ content [2]); // use str_replace to replace </p> In $ content [2] with \ r \ n print_r ($ content); exit ". ($ I + 1 ). "The section, title, and content are connected together with the variable $ result =" \ r \ n ". ($ I + 1 ). "Section --------". $ title. "_ Miss Wang is Shuai --------- \ r \ n ". $ content; writer ($ result ,". /ailaopo /". $ bookname. ". txt "," a + "); // call the function to echo $ result" novel ". $ bookname. "Total ". $ bookzj. "section, now sort it to section ". $ I. "Section _". $ title."
";} Echo" novels ". $ bookname." total ". $ bookzj." The section has been fully organized! "; Function writer ($ content, $ url, $ mode) // defines the function name writer parameter $ content, $ url, $ mode {$ fp = fopen ($ url, $ mode); // open the file $ url fwrite ($ fp, $ content); // Put $ content into $ fp fclose ($ fp ); // Close $ fp}?>