Jnerocorp Posted September 8, 2011 Share Posted September 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246751-backlink-checker-check-anchor-text-matches-from-database/ Share on other sites More sharing options...
requinix Posted September 9, 2011 Share Posted September 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246751-backlink-checker-check-anchor-text-matches-from-database/#findComment-1267210 Share on other sites More sharing options...
Jnerocorp Posted September 9, 2011 Author Share Posted September 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246751-backlink-checker-check-anchor-text-matches-from-database/#findComment-1267215 Share on other sites More sharing options...
requinix Posted September 9, 2011 Share Posted September 9, 2011 Solved? Here, let me make a small adjustment to the code I already posted: SELECT 1 FROM allowed_anchors WHERE anchor = 'Google' Ta da! Quote Link to comment https://forums.phpfreaks.com/topic/246751-backlink-checker-check-anchor-text-matches-from-database/#findComment-1267511 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.