Posted By

codingforever99 on 10/29/14


Tagged

php seo rank alexa


Versions (?)

Get alexa rank using php


 / Published in: PHP
 

URL: http://function-code.blogspot.com/2014/10/get-alexa-rank-using-php.html

Getting alexa rank is simple, a data link provide by alexa only needs the domain name and then it return xml data including the rank we want, so I make a php function to do this task.

  1. <?
  2. function Get_Alexa_Rank($domain)
  3. {
  4. $alexa = "http://data.alexa.com/data?cli=10&dat=s&url=%s";
  5. $request_url = sprintf($alexa, urlencode($domain));
  6.  
  7.  
  8. $xml = simplexml_load_file($request_url);
  9.  
  10. if (!isset($xml->SD[1])) {
  11. return FALSE;
  12. }
  13. $nodeAttributes = $xml->SD[1]->POPULARITY->attributes();
  14. $text = (int) $nodeAttributes['TEXT'];
  15.  
  16. return $text;
  17. }
  18.  
  19.  
  20. //example:
  21. echo "The alexa rank for Google is :". Get_Alexa_Rank('google.com') ."<BR>";
  22. echo "The alexa rank for blogger is :". Get_Alexa_Rank('blogger.com') ."<BR>";
  23.  
  24. ?>

Report this snippet  

You need to login to post a comment.