A programming & designing blog!

Friday, October 4, 2013

Get Alexa Rank with PHP

Alexa is one of the most well known and poplar web information provider. It provides information like web site's traffic status, reviews, back links and many more. The most important thing of Alexa is, it measures web site's popularity and provides its global rank. And this rank is accepted by all. Though it is very easy to know a web site' Alexa rank from Alexa's website. But now I going to show you a way to get Alexa rank with PHP code.

Alexa Rank Checker PHP Function

 * Alexa Rank with PHP
 * @param string $domain (www.w3bes.com)
 * @return int || void
function alexa($domain){
  $uri = 'http://data.alexa.com/data?cli=10&dat=snbamz&url=';
  $uri .= $domain;

  $xml = simplexml_load_file($uri);

  if (isset($xml->SD[1]->POPULARITY))
    return (int) $xml->SD[1]->POPULARITY->attributes()->TEXT;


echo alexa('w3bees.com');