PHP Script to Fetch the Alexa Rank of a Website

Basically, Alexa rank is the frequency of visits on a particular website. Lower Alexa rank means more traffic volume to that website. Its ranking system is based on information collected from users who have installed its toolbar.

In this post, I will show you to fetch the Alexa rank of a particular website using a simple PHP script. To get the alexa rank, all you need to do is pass the URL of website to getAlexaRank() function. The function will return the rank which can be further stored inside a variable or in the database, or can be simple 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');

Useful Read: Unzip a file with php

3 Comments

Leave a Comment.