A simple PHP collector that you write yourself
<?php
//****************************************************************
$url = "http://book.sina.com.cn/nzt/lit/zhuxian2/index.shtml";//Book Address
$ver = "old"; Old and new versions
//****************************************************************
$r = file_get_contents ($url); Open the Web address with file_get_contents and read the contents of the open page
Preg_match ("/<meta name=\" description\ "content=\" (. *?) \ ">/is", $r, $booktitle);//matches the title of this page
$bookname = $booktitle [1];//second-level array
$preg = '/<li><a href= (. *). shtml target=_blank class= "a03" >/isu ';
Preg_match_all ($preg, $r, $ZJ); Match the chapter connections for this page
$BOOKZJ = count ($zj [1]);//Calculate the number of chapter headings
if ($ver = = "new") {
$content _start = "<!--body Content started--";
$content _end = "<!--body content ended--";
}
if ($ver = = "old") {
$content _start = "<\/table><!--newszw_hzh_end-->";
$content _end = "<br>";
}
Header ("content-type:text/html;charset=gb2312");
Writer ($bookname. "Total". $bookzj. " Section \ r \ n Handsome guy Liu and in ". Date (" D M J g:i:s T Y ")." In order to graduate, the design of the novel collection \ r \ n ","./ailaopo/". $bookname. TXT "," w+ ");
for ($i =0; $i < $bookzj; $i + +) {
echo "http://book.sina.com.cn". $zj [1][$i] ". shtml";d ie ();
Open and read the contents of the open page by using file_get_contents to connect the chapter
$str = file_get_contents ("http://book.sina.com.cn". $zj [1][$i]. ". sHTML ");
Preg_match ("/(<title>) (. *?) (<\/title>)/is ", $str, $title);//Match the title of this connection page
$title = Str_replace ("_ Reading Channel _ Sina Net", "", $title [2]);//Put $title[2] There _ reading channels _ Sina Net change to empty
Preg_match ("/(". $content _start. ") (.*?) (". $content _end.") /is ", $str, $content);//Match the contents of this connection page
$content = Preg_replace ("/< (. *?) >/s "," ", Str_replace (" </p> "," \ r \ n ", $content [2])),//////////Str_replace $content[2] </p>
Print_r ($content);
Exit
Put the first. " ($i + 1). " Sections and headings are concatenated with the content in the variable
$result = "\ r \ n". ($i + 1). " Section--------". $title." _ Mr. Wang is handsome---------\ r \ n ". $content;
Writer ($result, "./ailaopo/". $bookname. ". TXT "," A + ");//Call function to $result
echo "novel". $bookname. " Total ". $bookzj." section, now tidy up to section ". $i." Section _ ". $title." <br> ";
}
echo "novel". $bookname. " Total ". $bookzj." The section has been all sorted and finished! ";
function writer ($content, $url, $mode)//define function name writer parameter $content, $url, $mode
{
$fp = fopen ($url, $mode);//Open File
Fwrite ($fp, $content);//Put $content into the $fp
Fclose ($FP); Close $FP
}
?>
A simple PHP collector that you write yourself