正则表达式获取具有rel ='nofollow'属性的锚标记

时间:2013-01-06 15:44:02

标签: php regex

  

可能重复:
  How to parse and process HTML/XML with PHP?

我想在html源代码中找到反向链接。请参阅下面的代码。 但我想找到没有rel='nofollow'属性的锚标签。

示例:

<a href='http://domain.com/abd/ff/' rel='nofollow'>

正则表达式:

if(preg_match("/<a(.*)href=[\"']".$match_pattern."(\/?)[\"'](.*)>(.*)<\/a>/", $part)){...}

功能:

function check_back_link($remote_url, $your_link) {
  $match_pattern = preg_quote(rtrim($your_link, "/"), "/"); 
  $found = false;
  if($handle = @fopen($remote_url, "r")){
    while(!feof($handle)){
      $part = fread($handle, 1024);
      if(preg_match("/<a(.*)href=[\"']".$match_pattern."(\/?)[\"'](.*)>(.*)<\/a>/", $part)){
        $found = true;
        break;
      }
    }
    fclose($handle);
  }
  return $found;
}

0 个答案:

没有答案