用php的方法取谷歌的PR值。事实上我已经很久没关注PR值了,PR值 也不像以前那样备受关注,影响力有所下降。

function pagerank($domain)
{
$StartURL = "http://toolbarqueries.google.com/tbr?client=navclient-auto&features=Rank&q=info:";
$GoogleURL = $StartURL.$domain. '&ch='.HashURL($domain);
$fcontents = file_get_contents("$GoogleURL");
$pagerank = substr($fcontents,9);
if (!$pagerank) return "0";else return $pagerank;
}
 
function HashURL($url)
{
$SEED = "Mining PageRank is AGAINST GOOGLE’S TERMS OF SERVICE.";
$Result = 0x01020345;
for ($i=0; $i<strlen($url); $i++) { $Result ^= ord($SEED{$i%87}) ^ ord($url{$i}); $Result = (($Result >> 23) & 0x1FF) | $Result << 9;
}
return sprintf("8%x", $Result);
}
 
echo pagerank("saycn.net");

如果是64位的系统,上面的代码运行不了,HashURL的函数换为下面的。

function HashURL($url)
{
$SEED = "Mining PageRank is AGAINST GOOGLE’S TERMS OF SERVICE.";
$Result = 0x01020345;
for ($i=0; $i<strlen($url); $i++) { $Result ^= ord($SEED{$i%87}) ^ ord($url{$i}); $Result = (($Result >> 23) & 0x1FF) | $Result << 9 & 0xFFFFFFFF;
}
return sprintf("8%x", $Result);
}