Friday, January 9, 2015

How to Fetch the Alexa Rank of the Website with PHP Script

Alexa rank is a most important factor of any particular website. It is a frequency of visits on a website. Lower Alexa rank means higher traffic to that website. Its ranking system is based on information collected from users who have installed its toolbar.

Fetch the Alexa Rank of the Website

Here, You will find, how to fetch the Alexa rank of a particular website with suing a simple PHP script. To get the Alexa rank, we have to pass the URL of a website to getAlexaRank() function.
The function will return the rank which can further be stored inside a variable or in the database, or can be displayed on screen.

//PHP Script to Fetch Alexa Rank

function getAlexaRank($url){
$xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$url);
$rank=isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
return $rank;
}
echo getAlexaRank('http://coffeecupweb.com');

0 comments:

Post a Comment