- Joined
- Mar 30, 2017
- Messages
- 21
- Likes
- 26
- Degree
- 0
I've been really digging into my competitor research lately, looking at their links both internal and external.
I'm not a dev but to do some of the heavy lifting I've put together a little script to categorise anchor.
Obviously, you'll need to plug this into your own data with a loop and there's still a lot of development to do but it does the job for a quick overview.
If anyone wants to DRY it up or improve it (for basic use) please update this thread to keep it current.
I'm not a dev but to do some of the heavy lifting I've put together a little script to categorise anchor.
Obviously, you'll need to plug this into your own data with a loop and there's still a lot of development to do but it does the job for a quick overview.
If anyone wants to DRY it up or improve it (for basic use) please update this thread to keep it current.
PHP:
<?php
$domain = "buildersociety.com";
$keyword = strtolower("best cat beds for large cats");
$keyword_count = str_word_count($keyword);
$keyword_array = explode(" ",$keyword);
// IMAGE TEST
// $anchor = '';
// EXACT MATCH TEST
// $anchor = strtolower('best cat beds for large cats'); -- PASSES
// $anchor = strtolower('best beds for larger cats'); -- PASSES
// $anchor = strtolower('here are six words on topic'); -- PASSES
// PHRASE MATCH TEST
// $anchor = strtolower("best best cat beds for large cats who like heights"); -- PASSES
// $anchor = strtolower("best beds for cats"); -- PASSES
// $anchor = strtolower('here are four words plus one more');
//URL LINK TEST
// $anchor = strtolower("https://www.buildersociety.com"); -- PASSES
// $anchor = strtolower("https://www.buildersociety.com/forums/digital-strategy-crash-course.25/"); --PASSES
// COUNT THE WORDS
$anchor_count = str_word_count($anchor);
if(stripos($anchor, $domain) !== FALSE){
// LETS DEAL WITH THE DOMAIN CHECK FIRST
echo "URL MATCH";
}elseif (str_word_count($anchor) == 0){
// LETS DEAL WITH THE IMAGE NEXT
echo 'IMAGE MATCH';
}elseif($keyword_count == $anchor_count){
// IF THE WORD COUNT MATCHES THEN WE NEED TO SEE IF IT MATCHES 100% ELSE SEE IF IT'S A PARTIAL MATCH
if (stripos($anchor, $keyword) === FALSE) {
if(0 < count(array_intersect(array_map('strtolower', explode(' ', $anchor)), $keyword_array))){
echo "PARTIAL MATCH";
}else{
echo "MISC MATCH (count same)";
}
}else{
echo "EXACT MATCH";
}
}elseif($anchor_count !== $keyword_count){
// IF ANCHOR TEXT COUNT IS > KEYWORD COUNT
// FIRST CHECK TO SEE IF THE EXACT PHRASE IS USED IN THE ANCHOR
if (stripos($anchor, $keyword) === FALSE) {
if(0 < count(array_intersect(array_map('strtolower', explode(' ', $anchor)), $keyword_array))){
echo "PARTIAL MATCH (count difference)";
}else{
echo "MISC MATCH (count difference)";
}
}else{
echo "PHRASE MATCH";
}
}
?>