PHP获取谷歌PR值-最新代码

    1. <?php   
    2.   
    3.  /* 
    4. *功能:对URL进行编码 
    5. *参数说明:$web_url 网站URL,不包含"http://",例如soqi.cc 
    6.    
    7. *来源:http://blog.micxp.com 
    8. */  
    9. function HashURL($url){   
    10.     $SEED = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer.";   
    11.     $Result = 0x01020345;   
    12.     for ($i=0; $i<strlen($url); $i++)   
    13.     {   
    14.         $Result ^= ord($SEED{$i%87}) ^ ord($url{$i});   
    15.         $Result = (($Result >> 23) & 0x1FF) | $Result << 9;   
    16.     }   
    17.     return sprintf("8%x"$Result);   
    18. }   
    19. /* 
    20. *功能:获取pagerank 
    21. *参数说明:$domain 网站域名,不包含"http://", 
    22.    
    23. *来源:http://yi1.com.cn 
    24.    
    25. */  
    26. function pagerank($domain)   
    27. {       
    28.     $StartURL = "http://toolbarqueries.google.com/tbr?client=navclient-auto&features=Rank:&q=info:";   
    29.     //    $StartURL = "http://www.google.com/search?client=navclient-auto&features=Rank:&q=info:";  
    30.     $GoogleURL = $StartURL.$domain. '&ch='.HashURL($domain);   
    31.     $fcontents = file_get_contents("$GoogleURL");   
    32.     $pagerank = substr($fcontents,9);   
    33.     if (!$pagerankreturn "0";else return $pagerank;   
    34. }   
    35.   
    36. echo pagerank("www.soqi.cc");
posted @ 2013-03-06 14:40  潇湘双雁  阅读(213)  评论(0)    收藏  举报