这东西不太好说.具体情况具体考虑.我给你一个例子.希望你可以从中得到思路
<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
/*
*心若水寒
*/
*/
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("<","<\\",$array[0][0]);CnPhper.com By Cnphper CnPhperFrom CnPhper.com
//$array[0][0] = str_replace(">","\\>",$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(" "," ",$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);
}
}
?>
(非常全面的一个php技术网站, 有相当丰富的文章和源代码.)
|