[转]PHP采集教程示例
2012-1-30 17:38 Monday  

分类: PHP 评论(48) 浏览(31081)

<form id="form1" name="form1" method="post" action="">
   <input type="text" name="start" />
  到
  <input type="text" name="end" />
   <input type="submit" name="Submit" value="提交" />
   <input type="reset" name="Submit2" value="重置" />
</form>

<?php /* *心若水寒 *http://www.phpfans.net/ */ if(isset($_POST['Submit'])){ $conn = mysql_connect("localhost","root",""); mysql_query("set names 'gbk'"); mysql_select_db("caiji2"); for($i=$_POST['start'];$i<=$_POST['end'];$i++){ $url = "http://www.phper.com/html/php-mysql/".$i.".html"; @$fp = fopen($url,'r'); if(!$fp) continue; $buffer = ''; while(@!feof($fp)){ $buffer .= @fread($fp,1024); } preg_match_all("/<h1>(.+?)</h1>/is",$buffer,$title); $title[0][0] = preg_replace("/<h1>(.+?)</h1>/is","1",$title[0][0]); $title = explode("——",$title[0][0]); $ar_subject = $title[0]; //echo $ar_subject;exit; preg_match_all("/<div class="content">(.+?)</div>/s",$buffer,$array); //echo $array[0][0];exit; //preg_match_all("/(.+)<br>/is",$array[0][0],$array); //$array[0][0] = str_replace("&lt;","<",$array[0][0]);CnPhper.com By Cnphper CnPhperFrom CnPhper.com //$array[0][0] = str_replace("&gt;",">",$array[0][0]); //$array[0][0] = htmlspecialchars($array[0][0]); //$array[0][0] = str_replace("<BR>","n",$array[0][0]); //$array[0][0] = str_replace("&nbsp;"," ",$array[0][0]); $ar_content = strip_tags($array[0][0],"<br>"); //$ar_content = str_replace("From CnPhper.com","",$ar_content); //$ar_content = preg_replace("/CnPhper.com/i","",$ar_content); //echo $ar_content;exit; //$ar_content = substr($array[0][0],14,-6); $sql = "insert into cdb_article values(null,'未知','".addslashes($ar_subject)."','".addslashes($ar_content)."','互联网','2006-07-20',0,4,0,1,0)"; mysql_query($sql,$conn); fclose($fp); } } ?>

+1 15

留下你的看法: