注意使用属性进行互惠链接

时间:2016-08-27 07:55:11

标签: php

我想建立一个链接交换网站。我想知道我的朋友们如何对待我网站上的链接。 到目前为止,我已经找到了一个PHP脚本来检测我何时从其网站上删除了链接。但这对我来说还不够。

我预计:我怎么知道我的朋友是否作弊,例如将rel="dofollow"更改为rel="nofollow" 另外,我想在其网站上知道一个指向网址Domain.com

的链接

我非常感谢你的任何意见。

我的脚本代码:

<?php
$mydomain = "http://Domain.com"; // Set this to your domain
$list = file_get_contents("list_uri.txt");
$urls = explode ("\n", $list);
echo "<B>Checking $mydomain</B><P><FONT SIZE=-1>";
foreach ($urls as $url) {
if (strlen ($url)) {
echo $url . "<B><FONT COLOR=";
if (strpos (file_get_contents($url), $mydomain) != FALSE) {
echo "GREEN> Link Installed!";
} else {
echo "RED> Link Not Installed!";
}
echo "</FONT></B><BR>";
}
}
echo "</FONT>";
?>

1 个答案:

答案 0 :(得分:0)

您无法知道您的朋友在其代码中添加标签或其他特殊字符。您应该使用Simple HTML Dom Parser解析HTML,它非常易于使用:

$urlContents = file_get_html($url);
$elements = $urlContents->find('a[rel="dofollow"][href="'.$myDomain.'"]');
if(count($elements) > 0){
    /*Correct structure. You can loop elements with foreach($elements as $element) */
}else{
    //HTML doesn't have on.
}

http://simplehtmldom.sourceforge.net/