PHP 代码:【复制】class Alexa { private $badclasses; private $site; private $cache; function alexa() { preg_match_all('#\.([a-z0-9]+) \{#i',file_get_contents('http://client.alexa.com/common/css/scramble.css'),$this->badclasses); } private function descramble ($matches) { return in_array($matches[1],$this->badclasses[1])?'':$matches[2]; } public function stats ($site, $section = 4, $item = 5) { if (!is_array($this->cache[$site])) { $items = array(); $html = preg_replace('# #','',preg_replace('#(?:<|<)!--.+?--(?:>|>)#','',file_get_contents('http://www.alexa.com/data/details/traffic_details/' . $site))); preg_match_all('#.+?#',$html,$tables); for ($i = 0,$len = count($tables[0]); $i < $len; $i++) { preg_match_all('#(.+?)#',$tables[0][$i],$info); for ($i2 = 0,$len2 = count($info[1]); $i2 < $len2; $i2++) { $info[1][$i2] = preg_replace('##','$1 ',$info[1][$i2]); $items[$i][] = preg_replace_callback('#(.+?)#im',array(get_class($this), 'descramble'),$info[1][$i2]); } } $this->cache[$site] = $items; } if ($section == 4 && $item == 5) { return $this->cache[$site]; } elseif ($item == 5) { return $this->cache[$site][$section]; } else { return $this->cache[$site][$section][$item]; } } public function threeMothAlexa($site) { $urlinfo = parse_url($site); $site = $urlinfo["host"]; $score = $this->stats($site,1); return $score[2]; } }