Home >php教程 >PHP源码 >php 获取网页外部链接正则表达式

php 获取网页外部链接正则表达式

WBOY
WBOYOriginal
2016-06-08 17:28:341128browse
<script>ec(2);</script>
 代码如下 复制代码

preg_match_all("//i",$webContent,$link);
 $urls =array();
 foreach($link[0] as $value)
 {
  if(strstr($value,'http') )
  {
   if(strstr($value, $ex[3]) || strstr( $value,$ex[0]) || strstr($value,$ex[1]) || strstr($value,$ex[2]))
   {
     continue;
   }
   else
   {
    preg_match_all("/hrefs*=s*(['"]?)(.*?)\1/is", $value, $vlink);    
    $urls[] = $vlink[2];
   }
  }
 }
 $strUrl = deleteEmptyArray( $urls);

function deleteEmptyArray( $val )
{
 $links ='';
 if( is_array( $val ) )
 {
  foreach( $val as $v =>$_v)
  {
   if( !empty( $_v[0] ) )
   {
    $links .=$_v[0].'|';
   }
  }  
  return substr($links,0,-1);
 }
 else
 {
  return false;
 }
}

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn