Jump to content

Backlink Checker, Check Anchor Text matches from database


Jnerocorp

Recommended Posts

Hello,

 

I am trying to get this backlink checker to work i have it working so it checks that the link itself matches and is there but this is the harder part that I don't understand.

 

I want to have it also check the nodeValue to make sure that it matches one of the nodeValue's from a mysql table

 

this is the code I have to make it check the href link

 

function CheckForTargetUrl($links, $target) {    
    foreach ($links as $link) {
        if (strpos($link, $target) !== false) {
            return true;
        }
    }

    return false;
} 
                          
function ExtractHrefLinks($html) {
    $dom = new DOMDocument;
    $linkUrls = array();
     

    @$dom->loadHTML($html);
    $links = $dom->getElementsByTagName('a');
     
    foreach ($links as $link){
        $linkUrls[] = $link->getAttribute('href');
    }
    
    return $linkUrls;
}

function backlink_check($contenturl){

$url = 'businessinvestingsource.com';
$source = $contenturl;

$falseFound = false;

    $html = file_get_contents ( $source );
    $links = ExtractHrefLinks($html);

    if (CheckForTargetUrl($links, $url) === false) {
        $falseFound = "true";
        $reportArray[$source] = 0;
    } else {
        $falseFound = "false";
    }

return $falseFound;
}

 

Now this all works fine, I just need it to check the actual nodeValue (anchor text as well) meaning check this:

 

<a href="http://google.com">Google</a>

 

There is a mysql table called "allowed_anchors" with 2 rows "id" and "anchor"

 

I need it to check if the nodeValue matches 1 of the allowed_anchors from the table.

 

If anyone knows how I can do this that would be very great i have been trying to figure it out for hours with no luck.

 

Thanks very much for any help to come.

Link to comment
Share on other sites

You have just that one "anchor" in the table. It's either the URL or the anchor text. It isn't both. So you're missing one or the other.

 

Once you've put that into the table, do a SQL query like

SELECT 1 FROM allowed_anchors WHERE text = 'Google' AND anchor = 'http://google.com'

If you get any rows back then the link is valid, otherwise it isn't.

Link to comment
Share on other sites

i don't think you understand what I mean.

 

What I am checking is if http://example.com/ has a backlink to my site. and both the bolded parts must match:

 

<a href="http://google.com">Google</a>

 

I already have it able to make sure http://google.com matches, but I need to make sure Google Matches whats in the table row(allowed_anchors) so if the word "Google" is one of the anchor(s) in the table then it matches

 

lets say the table looked like this:

| id | anchor |

| 0 |  Google  |

| 1 |  Yahoo  |

| 2 |  Bing  |

 

if the backlink on example.com looked like this:

 

<a href="http://google.com">Search</a> then "Search" is not in the table so it doesnt match.

 

So what I need to know is

How to check the word "Search" (or whatever it may be) in the backlink to make sure it matches one of the anchor(s) in the table.

 

I Hope this clarifies.

 

Thanks :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.