由于需要我做了個函數,實現取得頁面連接放到數組里 思路:1,取得靜態+不帶參數的: htm html asp php jsp cgi a,包含絕對路徑的處理:直接取得 preg_match_all ()? b,包含相對路徑的,路徑得到處理參數: 根據情況(. 或 .. )處理得到絕對路徑 2,取得帶參數的: 3,經過篩選:選擇了一些可以讀的后綴比如asp,php,html等 連接重復的進行刪除。 4,直接運行代碼就把 落伍者論壇 » 網站建設專欄 第一頁面的連接拿下來到數組$e中,$e[o][0]為第一個連接;$e[o][1]為第2個 | code: | | <? $e=clinchgeturl("http://im286.com/forumdisplay.php?fid=1"); var_dump($e); function clinchgeturl($url) { //$url="http://127.0.0.1/1.htm"; //$rootpath="http://fsrootpathfsfsf/yyyyyy/"; //var_dump($rrr); if(eregi('(.)*[/.](.)*',$url)){ $roopath=split("http://",$url); $rootpath="http://".$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:]:@/._-]+)(/"?)',"http://2",$regs[1]); $regs[1] = eregi_replace('(href[[:space:]]*=[[:space:]]*[/"]?)([[:alnum:]:@/._-]+[/?]?[^/"]*)(/.*)[^/"http://]*([/"]?)',"http://2",$regs[1]); if(!eregi('^http:////',$regs[1])){ if(eregi('^/./.',$regs[1])){ // $roopath=eregi_replace('(http:////)?([[:alnum:]:@/._-]+)[[:alnum:]+](/.*)[[:alnum:]+]',"http://////2",$url); $roopath=split("http://",$rootpath); $rootpath="http://".$roopath[2]."/"; //echo "這是根本d :"."/n"; $nnn=count($roopath)-1;for($yu=3;$yu<$nnn;$yu++){$rootpath.=$roopath[$yu]."/";} //var_dump($rootpath); if(eregi('^/./.[//[:alnum:]]',$regs[1])){ //echo "這是../目錄/ :"."/n"; //$regs[1]="../xx/xxxxxx.xx"; // $rr=split("http://",$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; } ?> |
|
|