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: ?>
2 Comments
good
nice to see that someone is stealing my work.
http://scriptasy.com/showthread.php?t=134
Post a Comment