0

这是我想做的..

假设我在http://example.com/test.html的文件中寻找链接“example.com ”。

我想采用一个在上述网站中查找的 PHP 脚本。但是,如果<A>.

4

2 回答 2

2

见下面网址

如何通过 PHP 检查 URL 是否存在?

或尝试一下

$file = 'http://www.domain.com/somefile.jpg';
$file_headers = @get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
    $exists = false;
}
else {
    $exists = true;
}

从这里:http ://www.php.net/manual/en/function.file-exists.php#75064

...在上述帖子的正下方,有一个 curl 解决方案:

function url_exists($url) {
    if (!$fp = curl_init($url)) return false;
    return true;
}

更新代码:-

您可以使用 SimpleHtmlDom 类在标签中查找 id 或类

请参阅以下网址

http://simplehtmldom.sourceforge.net/

http://simplehtmldom.sourceforge.net/manual_api.htm

http://sourceforge.net/projects/simplehtmldom/files/

http://davidwalsh.name/php-notifications

于 2012-09-06T19:26:28.967 回答
0

这是我发现的以防其他人也需要它!

  $url = "http://example.com/test.html";
  $searchFor = "example.com"
  $input = @file_get_contents($url) or die("Could not access file: $url");
  $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
  if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) {
    foreach($matches as $match) {
      echo $match[2];
      if ($match[2] == $searchFor)
      {
          $isMatch = 1;
      } else {
          $isMatch= 0;
      }
      // $match[0] = A tag
      // $match[2] = link address
      // $match[3] = link text
    }
  }

      if ($isMatch)
      {
          echo "<p><font color=red size=5 align=center>The page specified does contain your link. You have been credited the award amount!</font></p>";
      } else {
          echo "<p><font color=red size=5 align=center>The specified page does not have your referral link.</font></p>";
      }
于 2012-09-06T19:23:17.997 回答