关于在线取得PR值的代码
时间:2005-04-30 来源:litie123
转自
http://blog.csdn.net/stefenjun/archive/2005/04/15/349397.aspx
[url=http://blog.csdn.net/angelz/archive/2005/03/26/331254.aspx][/url]
error_reporting(E_ALL & ~E_NOTICE);
$header =
WAPH;
$footer = getrank();
echo $header;
echo "你网站的PageRank = $pagerank";
echo $footer;
/**
* 取得google PageRank 数值
**/
class getPR
{
var $google_magic = 0xE6359A60;
var $url = 'www.n139.com';
function getPR($url = "")
{
if ("" != $url) $this->url = $url;
}
function zeroFill($a, $b)
{
$z = hexdec(80000000);
if ($z & $a) {
$a = ($a>>1);
$a &= (~$z);
$a |= 0x40000000;
$a = ($a>>($b-1));
} else {
$a = ($a>>$b);
}
return $a;
}
function mix($a, $b, $c)
{
$a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,13));
$b -= $c; $b -= $a; $b ^= ($azeroFill($b,13));
$a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,12));
$b -= $c; $b -= $a; $b ^= ($azeroFill($b,5));
$a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,3));
$b -= $c; $b -= $a; $b ^= ($azeroFill($b,15));
return array($a,$b,$c);
}
function GoogleCH($url, $length=null, $init = "")
{
if ("" == $init) $init = $this->google_magic;
if(is_null($length)) $length = sizeof($url);
$a = $b = 0x9E3779B9;
$c = $init;
$k = 0;
$len = $length;
while($len >= 12)
{
$a += ($url[$k+0] +($url[$k+1]mix($a,$b,$c);
$a = $mix[0]; $b = $mix[1]; $c = $mix[2];
$k += 12;
$len -= 12;
}
$c += $length;
switch($len)
{
case 11: $c+=($url[$k+10]mix($a,$b,$c);
return $mix[2];
}
function strord($string)
{
for($i=0; $i $result[$i] = ord($string{$i});
}
return $result;
}
function getrank()
{
$this->url = 'info:' . $this->url;
$file = "http://www.google.com/search?client=navclient-auto&ch=6".$this->GoogleCH($this->strord($this->url))."&features=Rank&q=".$this->url;
$data = $this->naps_get_html($file);
if ($data) {
$rankarray = explode (':', $data);
$rank = $rankarray[2];
return $rank;
} else {
return '取得远程文件错误!';
}
}
function naps_get_html($file)
{
$fp = @fopen($file, 'rb');
if ($fp) {
do {
$urldata = @fread($fp, 8192);
if (strlen($urldata) == 0) break;
$result .= $urldata;
} while(true);
return $result;
} else {
return false;
}
}
}
?>
相关阅读 更多 +