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.
< ?
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ão existe.');
}
}
$domain = "blue.muiomuio.net";
$alexa_connector = new alexa('http://alexa.com/xml/dad?url=',$domain);
// estilo 1
echo '
Alexa Rank: '.$alexa_connector->get('rank').' '.$domain.'
';
// estilo 2
echo '
'.$alexa_connector->get('rank').'
';
?>
