Feed on
Posts
Comments

Иногда необходимо убедиться в том, что конкретной странице действительно есть конкретная ссылка.

  1. function contains_link($page_url, $link_url) {
  2.         /* Get the page at page_url */
  3.     $ch = curl_init();
  4.     curl_setopt($ch, CURLOPT_URL, $page_url);
  5.     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  6.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  7.  
  8.     curl_setopt($ch, CURLOPT_USERAGENT,
  9.       ‘Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)’);
  10.  
  11.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  12.     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  13.     curl_setopt($ch, CURLOPT_FAILONERROR, true);
  14.  
  15.     $html = curl_exec($ch);
  16.     curl_close($ch);
  17.  
  18.     if(!$html) return false;
  19.  
  20.     /* Remove HTML comments and their contents */
  21.     $html = preg_replace(‘/<!–.*–>/i’, ‘’, $html);
  22.  
  23.     /* Extract all links */
  24.     $regexp=‘/(<a [\s]+[^>]*href\s*=\s*[\”\’]?)([^\’\” >]+)([\’\”]+[^<>]*>)/i’;
  25.     if (!preg_match_all($regexp, $html, $matches, PREG_SET_ORDER)) {
  26.             return false; /* No links on page */
  27.     };
  28.  
  29.     /* Check each link */
  30.     foreach($matches as $match){
  31.             /* Skip links that contain rel=nofollow */ 
  32.             if(preg_match(‘/rel\s*=\s*[\’\”]?nofollow[\’\”]?/i’, $match[0])) continue;
  33.             /* If URL = backlink_url, we’ve found the backlink */
  34.             if ($match[2]==$link_url) return true;
  35.     }
  36.  
  37.     return false;
  38. }
  39.  
  40. /* Usage example */
  41.  
  42. if (contains_link(‘http://w-shadow.com/’,‘http://w-shadow.com/blog/’)) {
  43.         echo ‘Reciprocal link found.’;
  44. } else {
  45.         echo ‘Reciprocal link not found.’;
  46. };
  47. </a>

источник W-Shadow.com

Trackback URI | Comments RSS

Leave a Reply

Stocking Club’s Blog © 2008 | MistyLook made free by Reef Sandals