• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

取得页面所有不重复连接的函数_php

php 搞代码 7年前 (2018-06-21) 141次浏览 已收录 0个评论

  由于需要我做了个函数,实现取得页面连接放到数组
  思路:1,取得静态+不带参数的:
  htm html asp php jsp cgi
  a,包含绝对路径的处理:直接取得
  preg_match_all ()?
  b,包含相对路径的,路径得到处理参数:

http://www.gaodaima.com/48195.html取得页面所有不重复连接的函数_php

  根据情况(. 或 .. )处理得到绝对路径
  2,取得带参数的:
  3,经过筛选:选择了一些可以读的后缀比如asp,phphtml
  连接重复的进行删除。
  4,直接运行代码就把 落伍者论坛 » 网站建设专栏
  第一页面的连接拿下来到数组$e中,$e[o][0]为第一个连接;$e[o][1]为第2个
  
  

Code:
<?
  $e=clinchgeturl(“http://im286.com/forumdisplay.php?fid=1&#8221;);
  
  var_dump($e);
  function clinchgeturl($url)
  {
  
  //$url=”http://127.0.0.1/1.htm&#8221;;
  //$rootpath=”http://fsrootpathfsfsf/yyyyyy/&#8221;;
  //var_dump($rrr);
  if(eregi(‘(.)*[/.](.)*’,$url)){
   $roopath=split(“//”,$url);
   $rootpath=”http://&#8221;.$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])){
  
   if(eregi(‘^/./.’,$regs[1])){
   // $roopath=eregi_replace(‘(http:////)?([[:alnum:]:@/._-]+)[[:alnum:]+](/.*)[[:alnum:]+]’,”http://////2&#8243;,$url);
  
   $roopath=split(“//”,$rootpath);
   $rootpath=”http://&#8221;.$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(“//”,$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;
  }
  ?>

欢迎大家阅读《取得页面所有不重复连接的函数_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:取得页面所有不重复连接的函数_php
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址