教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php 获取网页外部链接正则表达式

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

发布时间:2016-10-28   编辑:jiaochengji.com
教程集为您提供php 获取网页外部链接正则表达式等资源,欢迎您收藏本站,我们将为您提供最新的php 获取网页外部链接正则表达式资源
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8853')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy8853>

preg_match_all("/<a(.*?)href=(.*?)</a>/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;
 }
}

 

您可能感兴趣的文章:
php获取站点的来路域名的方法
php 正则表达式获取网页所有网址和链接文字
常用正则表达式全集
PHP file_get_contents采集程序开发教程详解
爬虫入门的基本原理,如果你连这些都不知道那你可以放弃爬虫了!
php匹配图片地址的代码一例
PHP正则匹配日期和时间(时间戳转换)的例子
PHP正则匹配获取URL中域名的代码
python的爬虫是什么意思
google搜索引擎优化之链接策略

[关闭]
~ ~