directory backlink check

Discussion in 'PHP' started by stuart, Aug 13, 2007.

  1. #1
    Hi

    I need a spot of help from a knowledgeable php’er please.

    What I would like to do is have a function check for a backlink from dmoz and the yahoo dir.

    This is the current structure I have for checking backlinks through yahoo site explorer.

    
    /* 
    Function to check Yahoo Backlinks
    */ 
    function yahoo_back($url){ 
        $site = fopen('http://siteexplorer.search.yahoo.com/search?p='.urlencode($url).'&bwm=i&bwmf=a&bwms=p','r'); 
        while($cont = fread($site,1024657)){ 
            $total .= $cont; 
        } 
        fclose($site); 
        $match_expression = '/of about <strong>(.*) <\/strong>/Us'; 
        preg_match($match_expression,$total,$matches); 
        return $matches[1]; 
    } 
    
    Code (markup):
    What I need is to return a ‘0’ or ‘1’ on unsuccessful/successful find when checking the following domains…

    http://search.dmoz.org/cgi-bin/search?search=
    http://search.yahoo.com/search/dir?p=

    Cheers :)
     
    stuart, Aug 13, 2007 IP
  2. Wildhoney

    Wildhoney Active Member

    Messages:
    192
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    
    if(preg_match('/.*No Open Directory Project results found.*/iU', strip_tags($szSiteContent)))
    {
    	return false;
    }
    
    return true;
    
    PHP:
    Or something to the same effect.
     
    Wildhoney, Aug 13, 2007 IP
  3. stuart

    stuart Guest

    Messages:
    184
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your help! :)

    I have tried the following but I only get a positive '1' result never a negative. Any ideas what I may have wrong?

    /* 
    Function to check Dmoz Backlink
    */ 
           function getDmoz () {
                $site = fopen('http://search.dmoz.org/cgi-bin/search?search='.urlencode($url).'','r'); 
                if(preg_match('/.*No Open Directory Project results found.*/iU', strip_tags($szSiteContent))) {
                    $value = false;
                } else {
                    $value = true;
                }
                return $value;
            } 
    PHP:
     
    stuart, Aug 13, 2007 IP
  4. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Couple of problems with the code; I cleaned it up a little.

    1. You were calling fopen(), but not following it with an fread and fclose to actually get the site content. Replaced all of that with file_get_contents()
    2. You weren't passing in the $url paramter
    3. You passed a non-existent $szSiteContent variable to stript_tags(); replaced it with $site, which is what you intended

    Tested and works.

    
    function getDmoz($url) 
    {
    	$site = file_get_contents('http://search.dmoz.org/cgi-bin/search?search='.urlencode($url),'r'); 
    	return preg_match('/.*No Open Directory Project results found.*/iU', strip_tags($site)) ? false : true;
    }
    
    PHP:
     
    sea otter, Aug 13, 2007 IP
    stuart likes this.
  5. stuart

    stuart Guest

    Messages:
    184
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks to both of you! Cheers for your help :)
     
    stuart, Aug 13, 2007 IP
  6. ritadebock

    ritadebock Peon

    Messages:
    344
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    code is:
    function getDmoz($url)
    {
    $site = file_get_contents('http://search.dmoz.org/cgi-bin/search?search='.urlencode($url),'r');
    return preg_match('/.*No Open Directory Project results found.*/iU', strip_tags($site)) ? false : true;
    }
     
    ritadebock, Aug 22, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    file_get_contents() doesn't recognize the parameter "r".
     
    nico_swd, Aug 22, 2007 IP