2 years ago (2015-09-27 10:06:30)

Snippet: Fetch any Websites Alexa Rank using PHP

9 0
280
Hello reader, here is a small snippet function to find any sites alexa status. But if you make some little changes in codes, you can get more information from alexa like here we are fetching website's rank, people reach and backlinks. You can find more from alexa's developers API documentation forums or just Google it.
 
Its so simple to use just put any website in $url without http or ports (just use main host i.e infeeds.com).
 
<?php
function alexa_rank($site){
   $xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$site.'');
   $rank = isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
   $reach = isset($xml->SD[1]->RANK)?$xml->SD[1]->RANK->attributes()->RANK:0;
   $links = isset($xml->SD[1]->NUM)?$xml->SD[1]->NUM->attributes()->NUM:0;
   $host = (string)$xml->SD[0]->attributes()->HOST;
   $show = ''.$host.'\'s alexa ranking is '.$alexa.', reached '.$reach.' and has '.$links.' backlinks';
   return $show;
}
 
$url = 'infeeds.com'; /* without http:// or https:// */
$site = alexa_rank($url);
?>
 
Try to make new changes in this snippet, that will make you a better programmer. Just comment for more help.
 
Sign up or Sign in for free.
And start a new thread.
No Threads
More notes by Ghazi Khan