Get alexa rank using php


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.