Blue MUIOMUIO

Blogue pessoal de um Web Designer

Tutorial PHP: Alexa Rank

Tuesday August 05th 2008 Tutoriais

Embora muitos já usam o alexa rank para definir tops, estatutos, etc… mas pouca gente conhece o método de o usar sem ser através de aplicações já disponíveis na net.

Neste tutorial vou mostrar como criar um script que devolve o valor do Alexa Rank para um determinado site. O script pode ser facilmente adaptado para incorporar outras funções mais úteis.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
< ? 
class alexa {
 
    var $xml;
    var $values;
    var $alexa_address;
 
    function alexa($alexa_address,$domain) {
        $this->alexa_address = $alexa_address;
        $this->xml = $this->get_data($domain);
        $this->set();
    }
 
    function get_data($domain) {
        $url = $this->alexa_address.'http://'.$domain;
        $xml = simplexml_load_file($url) or die('Feed Indisponivel');
        return $xml;
    }
 
    function set() {
        $this->values['rank'] = ($this->xml->SD->POPULARITY['TEXT'] ? number_format($this->xml->SD->POPULARITY['TEXT']) : 0);
    }
 
    function get($value) {
        return (isset($this->values[$value]) ? $this->values[$value] : '"'.$value.'" n&atildeo existe.');
    }
}
 
$domain = "blue.muiomuio.net";
$alexa_connector = new alexa('http://alexa.com/xml/dad?url=',$domain);
 
// estilo 1
echo '<div style="width:150px; height:80px;">Alexa Rank:  '.$alexa_connector->get('rank').' <br /><span style="background:#efefef;"><a href="http://'.$domain.'">'.$domain.'</a></span></div>'; 
 
// estilo 2
echo '<div style="width:150px; height:80px;">'.$alexa_connector->get('rank').' <br /><img src="http://img171.imageshack.us/img171/1940/alexanl7.png" alt="alexa rank para '.$domain.'" title="'.$domain.' Alexa Rank" /></div>';
 
?>
Partilha: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • DoMelhor
  • EuCurti
  • Facebook
  • Mar.cant.es
  • Sapo
  • StumbleUpon
  • Technorati
  • Ueba
/ save to del.icio.us 0

 Sem Comentários
Deixa um comentário



Quebras de linha e parágrafo automáticas, endereço de -mail nunca será revelado, Tags HTML aceites: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line=""> , Comentários com * são obrigatórios

(*)

(*)