Skip to content

php查询alexa排名的代码

   1: <?PHP
   2: /*
   3: update: askie 
   4: Homepage: http://www.pkphp.com
   5: email: askie@sohu.com
   6: */
   7: class Alexa 
   8: {
   9: private $badclasses;
  10: private $site;
  11: private $cache;
  12:  
  13: function alexa() 
  14: {
  15: preg_match_all('#\.([a-z0-9]+) \{#i',file_get_contents('http://client.alexa.com/common/css/scramble.css'),$this->badclasses); 
  16: }
  17: private function descramble ($matches) {
  18: return in_array($matches[1],$this->badclasses[1])?'':$matches[2];
  19: }
  20: public function stats ($site, $section = 4, $item = 5) 
  21: {
  22: if (!is_array($this->cache[$site])) {
  23: $items = array();
  24: $html = preg_replace('# #','',preg_replace('#(?:<|<)!--.+?--(?:>|>)#','',file_get_contents('http://www.alexa.com/data/details/traffic_details/' . $site)));
  25: preg_match_all('#
  26:  
  27: .+? 
  28: #',$html,$tables);
  29:  
  30: for ($i=0,$len=count($tables[0]); $i<$len; $i++) {
  31: preg_match_all('#
  32:  
  33: (.+?) 
  34: #',$tables[0][$i],$info);
  35: for ($i2=0,$len2=count($info[1]); $i2<$len2; $i2++) {
  36: $info[1][$i2] = preg_replace('##','$1 ',$info[1][$i2]);
  37: $items[$i][] = preg_replace_callback('#(.+?)#im',array(get_class($this), 'descramble'),$info[1][$i2]);
  38: }
  39: }
  40: $this->cache[$site] = $items;
  41: }
  42: if ($section == 4 && $item == 5) {
  43: return $this->cache[$site];
  44: } elseif ($item == 5) {
  45: return $this->cache[$site][$section];
  46: } else {
  47: return $this->cache[$site][$section][$item];
  48: }
  49: }
  50: public function threeMothAlexa($site)
  51: {
  52: $urlinfo=parse_url($site);
  53: $site=$urlinfo["host"];
  54: $score=$this->stats($site,1);
  55: return $score[2];
  56: }
  57: }
  58: //
  59: //$alexa = new Alexa();
  60: //print_r($alexa->stats('www.pkphp.com'));
  61: //print_r($alexa->stats('www.pkphp.com',1));
  62: //print_r($alexa->stats('www.pkphp.com',1,1));
  63: //print_r($alexa->threeMothAlexa('http://www.pkphp.com/'));
  64: ?>

php 查询 alexa排名(1)http://client.alexa.com/common/css/scramble.css(1)http://client.alexa.com/common/css/scramble.css php(1)php Alexa 排名 代码(1)PHP获取alexa排名代码(1)php? 查詢(1)php 查询 alexa(1)alexa php(12)alexa php 代码(2)alexa php 查询(1)php查询alexa排名(1)alexa代码(1)Alexa排名PHP代码(1)php查询代码(1)PHP查询排名(1)

Share in Google Reader Share in Google Reader 分享到 FriendFeed 分享到 FriendFeed 推荐到豆瓣 推荐到豆瓣 分享到 Twitter 分享到 Twitter

2 Comments

  1. good

    Posted on 29-Jul-08 at 11:01 am | Permalink
  2. nice to see that someone is stealing my work.

    http://scriptasy.com/showthread.php?t=134

    Posted on 13-Aug-08 at 6:09 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*