Jnerocorp Posted September 9, 2011 Share Posted September 9, 2011 Hello, I am trying to get this backlink checker that checks to make sure another website has my link on their website, so far I can check to make sure the "href" link is there and is correct, but I cant get the textContent to prove valid or not it seems to always be proving true even when the textConent is not in the mysql database. The other persons website will have this: <a href="http://businessinvestingsorce.com">Business Investing Source</a> I need to make sure Business Investing Source (the textContent) matches the anchor in the database. Here is my code: <?php function CheckForAnchorMatch($anchortext) { $query = mysql_query("SELECT * FROM allowed_anchor WHERE anchor='$anchortext'"); if(mysql_num_rows($query) != 0) { return true; } return false; } 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 ExtractAnchorText($html) { $dom = new DOMDocument; $AnchorTexts = array(); @$dom->loadHTML($html); $links = $dom->getElementsByTagName('a'); foreach ($links as $link){ $AnchorTexts[] = $link->textContent; } return $AnchorTexts; } 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"; } $html = file_get_contents ( $source ); $anchortext = ExtractAnchorText($html); if (CheckForAnchorMatch($anchortext) === false) { $falseFound = true; } else { $falseFound = false; } return $falseFound; } ?> Help greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/246755-help-checking-if-dom-textcontent-matches-row-thats-in-database/ Share on other sites More sharing options...
Muddy_Funster Posted September 9, 2011 Share Posted September 9, 2011 that's not the best coding, also, do you have your targets sign off on the fact that you will be ripping all the link information from their page just to check if your link is there properly? what do you get if you return and print_r($links) from ExtractAnchorText()? is it populated properly? Quote Link to comment https://forums.phpfreaks.com/topic/246755-help-checking-if-dom-textcontent-matches-row-thats-in-database/#findComment-1267290 Share on other sites More sharing options...
Jnerocorp Posted September 9, 2011 Author Share Posted September 9, 2011 it says: DOMNodeList Object ( ) Quote Link to comment https://forums.phpfreaks.com/topic/246755-help-checking-if-dom-textcontent-matches-row-thats-in-database/#findComment-1267297 Share on other sites More sharing options...
Muddy_Funster Posted September 10, 2011 Share Posted September 10, 2011 looks like your html refference isn't bringing in relevent information when looking for the anchors. Why don't you just add an ID hash to your backlink and grab the details by using that? Quote Link to comment https://forums.phpfreaks.com/topic/246755-help-checking-if-dom-textcontent-matches-row-thats-in-database/#findComment-1267700 Share on other sites More sharing options...
Jnerocorp Posted September 11, 2011 Author Share Posted September 11, 2011 Well your idea makes sense but the problem is I am trying to make sure the user puts a valid backlink that has the proper href and innerhtml I dont want them to just put the link and leave the text blank so its a false link. Quote Link to comment https://forums.phpfreaks.com/topic/246755-help-checking-if-dom-textcontent-matches-row-thats-in-database/#findComment-1268085 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.