簡単なPHP収集器


<?php
  //**************************************************************** $url = "http://book.sina.com.cn/nzt/lit/zhuxian2/index.shtml" ;// $ver = "old" ; // //****************************************************************
  $r = file_get_contents ( $url ); // file_get_contents preg_match( "/<meta name=\"description\" content=\"(.*?)\">/is" , $r , $booktitle ); // $bookname = $booktitle [1]; // $preg = '/<li><a href=(.*).shtml target=_blank class=a03>/isU' ; preg_match_all( $preg , $r , $zj ); // $bookzj = count ( $zj [1]); // if ( $ver == "new" ){ $content_start = "<!-- -->" ; $content_end = "<!-- -->" ; } if ( $ver == "old" ){ $content_start = "<\/table><!--NEWSZW_HZH_END-->" ; $content_end = "<br>" ; }
  header( "Content-Type:text/html;charset=gb2312" );
  writer( $bookname . " " . $bookzj . " \r
"
. date ( "D M j G:i:s T Y" ). " \r
"
, "./ailaopo/" . $bookname . ".txt" , "w+" ); for ( $i =0; $i < $bookzj ; $i ++) { //echo "http://book.sina.com.cn".$zj[1][$i]".shtml";die(); // file_get_contents $str = file_get_contents ( "http://book.sina.com.cn" . $zj [1][ $i ]. ".shtml" ); preg_match( "/(<title>)(.*?)(<\/title>)/is" , $str , $title ); // $title = str_replace ( "_ _ " , "" , $title [2]); // $title[2] _ _ preg_match( "/(" . $content_start . ")(.*?)(" . $content_end . ")/is" , $str , $content ); // $content = preg_replace( "/<(.*?)>/s" , "" , str_replace ( "</p>" , "\r
"
, $content [2])); // str_replace $content[2] </p> \r
print_r( $content ); exit ; // ".($i+1)." $result = " \r
"
.( $i +1). " --------" . $title . "_ --------- \r
"
. $content ; writer( $result , "./ailaopo/" . $bookname . ".txt" , "a+" ); // $result echo " " . $bookname . " " . $bookzj . " , " . $i . " _" . $title . "<br>" ; } echo " " . $bookname . " " . $bookzj . " !" ;
  function writer( $content , $url , $mode ) // writer $content,$url,$mode { $fp = fopen ( $url , $mode ); // $url fwrite( $fp , $content ); // $content $fp fclose( $fp ); // $fp } ?>