Snippet: Fetch any Websites Alexa Rank using PHP

9 0 599 reads
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
function alexa_rank($site){
   $xml = simplexml_load_file(''.$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 = ''; /* 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.


Ghazi Khan /u/mgks

verified publisher79 feeds
No Threads
more feeds from /u/mgks