We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

fris on 07/27/08


Tagged

urlalexarankstats


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

jamesming
sumandahal


get alexa rank for a domain


Published in: PHP 


  1. <?
  2.  
  3. class alexa {
  4.  
  5. var $xml;
  6. var $values;
  7. var $alexa_address;
  8.  
  9. function alexa($alexa_address,$domain) {
  10. $this->alexa_address = $alexa_address;
  11. $this->xml = $this->get_data($domain);
  12. $this->set();
  13. }
  14.  
  15. function get_data($domain) {
  16. $url = $this->alexa_address.'http://'.$domain;
  17. $xml = simplexml_load_file($url) or die('Cannot retrieve feed');
  18. return $xml;
  19. }
  20.  
  21. function set() {
  22. $this->values['rank'] = ($this->xml->SD->POPULARITY['TEXT'] ? number_format($this->xml->SD->POPULARITY['TEXT']) : 0);
  23. }
  24.  
  25. function get($value) {
  26. return (isset($this->values[$value]) ? $this->values[$value] : '"'.$value.'" does not exist.');
  27. }
  28. }
  29.  
  30. $domain = "fark.com";
  31. $alexa_connector = new alexa('http://alexa.com/xml/dad?url=',$domain);
  32. echo 'alexa rank for '.$domain.' is '.$alexa_connector->get('rank');
  33.  
  34. ?>

Report this snippet 

You need to login to post a comment.