一般是本机运行,放到空间上是不明智的,因为不但很耗资源还需要支持远程抓取函数,比如file_get_contents($urls)file($url)等. <?
//2004-11-22
//$e=clinchgeturl("[url]im286.com/forumdisplay.php?fid=1");[/url]
//var_dump($e);
function clinchgeturl($url)
{
//$url="[url]127.0.0.1/1.htm";[/url]
//$rootpath="[url]fsrootpathfsfsf/yyyyyy/";[/url]
//var_dump($rrr);
if(eregi('(.)*[\.](.)*', $url))
{
$roopath = split("\/", $url);
$rootpath = "[url]"[/url].$roopath[2]."/";
$nnn = count($roopath) - 1;
for($yu = 3; $yu < $nnn; $yu++)
{
$rootpath. = $roopath[$yu]."/";
}
// var_dump($rootpath); //http: ,'',127.0.0.1,xnml,index.php
}
else
{
$rootpath = $url; //var_dump($rootpath);
}
if(isset($url))
{
echo "$url 有下列裢接:<br>";
$fcontents = file($url);
while(list(, $line) = each($fcontents))
{
while(eregi('(href[[:space:]]*=[[:space:]]*"?[[:alnum:]:@/._-]+[\?]?[^\"]*"?)', $line, $regs))
{
//$regs[1] = eregi_replace('(href[[:space:]]*=[[:space:]]*\"?)([[:alnum:]:@/._-]+)(\"?)',"\\2",$regs[1]);
$regs[1] = eregi_replace('(href[[:space:]]*=[[:space:]]*[\"]?)([[:alnum:]:@/._-]+[\?]?[^\"]*)(\.*)[^\"\/]*([\"]?)', "\\2", $regs[1]);
if(!eregi('^http:\/\/', $regs[1]))
{
f(eregi('^\.\.', $regs[1]))
{
//$roopath=eregi_replace('(http:\/\/)?([[:alnum:]:@/._-]+)[[:alnum:]+](\.*)[[:alnum:]+]',"http:\/\/\\2",$url);
$roopath = split("\/", $rootpath);
$rootpath = "[url]"">http://www.im286.com/foru[/url] ... d=1&page=$i
......
?>可以在后面利用$i的自动增加或范围来实现,比如$i++; <?
//2004-11-22 clinch
//$e=clinchgeturl("[url]test.com/forumdisplay.php?fid=1");[/url]
//var_dump($e);
function clinchgeturl($url)
{
//$url="[url]127.0.0.1/1.htm";[/url]
//$rootpath="[url]fsrootpathfsfsf/yyyyyy/";[/url]
//var_dump($rrr);
if(eregi('(.)*[\.](.)*', $url))
{
$roopath = split("\/", $url);
$rootpath = "[url]"[/url].$roopath[2]."/";
$nnn = count($roopath) - 1;
for($yu = 3; $yu < $nnn; $yu++)
{
$rootpath. = $roopath[$yu]."/";
}
// var_dump($rootpath); //http: ,'',127.0.0.1,xnml,index.php
}
else
{
$rootpath = $url; //var_dump($rootpath);
}
if(isset($url))
{
echo "$url 有下列裢接:<br>";
$fcontents = file($url);
while(list(, $line) = each($fcontents))
{
while(eregi('(href[[:space:]]*=[[:space:]]*"?[[:alnum:]:@/._-]+[\?]?[^\"]*"?)', $line, $regs))
{
//$regs[1] = eregi_replace('(href[[:space:]]*=[[:space:]]*\"?)([[:alnum:]:@/._-]+)(\"?)',"\\2",$regs[1]);
$regs[1] = eregi_replace('(href[[:space:]]*=[[:space:]]*[\"]?)([[:alnum:]:@/._-]+[\?]?[^\"]*)(\.*)[^\"\/]*([\"]?)', "\\2", $regs[1]);
if(!eregi('^http:\/\/', $regs[1]))
{
f(eregi('^\.\.', $regs[1]))
{
//$roopath=eregi_replace('(http:\/\/)?([[:alnum:]:@/._-]+)[[:alnum:]+](\.*)[[:alnum:]+]',"http:\/\/\\2",$url);
$roopath = split("\/", $rootpath);
$rootpath = "[url]".$roopath[2]."/";
//echo "这是根本d :"."\n";
$nnn = count($roopath) - 1;
for($yu = 3; $yu < $nnn; $yu++)
{
$rootpath. = $roopath[$yu]."/";
}
//var_dump($rootpath);
f(eregi('^\.\.[\/[:alnum:]]', $regs[1]))
{
//echo "这是../目录/ :"."\n";
//$regs[1]="../xx/xxxxxx.xx";
// $rr=split("\/",$regs[1]);
//for($oooi=1;$oooi<count($rr);$oooi++)
$rrr = $regs[1];
//{$rrr.="/".$rr[$oooi];
$rrr = eregi_replace("^[\.][\.][\/]", '', $rrr); //}
$regs[1] = $rootpath.$rrr;
}
}
else
{
if(eregi('^[[:alnum:]]', $regs[1]))
{
$regs[1] = $rootpath.$regs[1];
}
else
{
$regs[1] = eregi_replace("^[\/]", '', $regs[1]);
$regs[1] = $rootpath.$regs[1];
}
}
}
$line = $regs[2];
if(eregi('(.)*[\.](htm|shtm|html|asp|aspx|php|jsp|cgi)(.)*', $regs[1]))
{
$out[0][] = $regs[1];
}
}
}
}
for ($ouou = 0; $ouou < count($out[0]); $ouou++)
{
if($out[0][$ouou] == $out[0][$ouou+1])
{
$sameurlsum = 1;
//echo "sameurlsum=1:";
for($sameurl = 1; $sameurl < count($out[0]); $sameurl++)
{
if($out[0][$ouou+$sameurl] == $out[0][$ouou+$sameurl+1])
{
$sameurlsum++;
}
else
{
break;
}
}
for($p = $ouou; $p < count($out[0]); $p++)
{
$out[0][$p] = $out[0][$p+$sameurlsum];
}
}
}
$i = 0;
while($out[0][++$i])
{
//echo $root.$out[0][$i]."\r\n";
$outed[0][$i] = $out[0][$i];
}
unset($out);
$out = $outed;
return $out;
}
? >上面的东西只能zend,不然有碍市容:( <? php
function cut($file, $from, $end)
{
$message = explode($from, $file);
$message = explode($end, $message[1]);
return $message[0];
}
? >$from是列表前面的html代码 <? php
function getUrl($matches)
{
preg_match("/^(http:\/\/)?(.*)/i", $url, $matches);
return $matches[2];
}
? >2,获得:标题,内容 <? php
function getcontent($url)
{
f($handle = fopen ($url, "rb"))
{
$contents = "";
do
{
$data = fread($handle, 2048);
f (strlen($data) == 0)
{
reak;
}
$contents . = $data;
}
while(true);
fclose ($handle);
}
else
exit("........");
return $contents;
}
? >或者直接 preg_match("|<TITLE>(.*)</TITLE>|",$allcontent,$title);里面的<TITLE>(.*)</TITLE>部分通过提交表单得到. $a=ereg_replace("\n", '', $a);
$a=ereg_replace("\r", '', $a);去掉回车换行 $sql="INSERT INTO $articles VALUES ('', '$title', '', '$article','', '', 'clinch', 'from', '关键词', 1, '$栏目id', '$time', 1);\r\n\r\n";其中 $sql = "INSERT INTO article_articles VALUES ('', '$title', '', '$body','', '', 'clinch', 'sohu', 'php', 1, '#clinchall#', '$time', 1);然后不断积累查询语句内容,最后 $fname="what_"."_page".$i.".sql";
$fp = fopen("data/$f", 'w');
if(fputs($fp, $sql))
echo "file successfully write";
fclose($fp);根据前面的思路,非常不错 if(!empty($r_article) AND !empty($r_title))
{
$time = time();
$r_title = addslashes(trim($r_title));
$r_article = addslashes($r_article);
$get_sql = "INSERT INTO article_articles VALUES ('', '$r_title', '', '$r_article','', '', '', 'sohu', '', 1, '', '$time', 1);\r\n\r\n";
if(file_exists("xingfu_".$_SESSION['p'].".sql"))
{
if(filesize("xingfu_".$_SESSION['p'].".sql") > $mysize)
{
$_SESSION['p']++;
}
}
$fp = fopen("xingfu_".$_SESSION['p'].".sql", 'a');
fwrite($fp, $get_sql);
fclose($fp);
}先判断是否得到标题和内容,然后生成sql语句放到文本中,还可以判断大小分页生成. $DB->query("INSERT INTO `xxx` ( `xx` , `title` , `texts` , `sortid` ) VALUES ('', '".addslashes($title)."', '".addslashes($text)."', '".$mm."')");4,问题 |