Get alexa rank using php

get alexa rank using php

Alexa is one of the most famous sites to check traffic statistics for any site, and it make a global ranks for all sites depending on the visitors traffic, getting small number in alexa is better for your site to be more popular. Millions of people from all over the world visit Alexa to get the data they need to make smart business decisions. Search Alexa to discover the most successful sites on the web by keyword, category, or country.

Get alexa rank using php.

Getting alexa rank is simple, a data link provide by alexa only needs the domain name and then it return xml data including the rank we want, so I make a php function to do this task.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?
function Get_Alexa_Rank($domain)
{
    $alexa = "http://data.alexa.com/data?cli=10&dat=s&url=%s";
    $request_url =  sprintf($alexa, urlencode($domain));
 
 
    $xml = simplexml_load_file($request_url);
 
    if (!isset($xml->SD[1])) {
        return FALSE;
    }
    $nodeAttributes = $xml->SD[1]->POPULARITY->attributes();
    $text = (int) $nodeAttributes['TEXT'];
 
    return $text;
}
 
?>


Call the php function to get alexa rank.

1
2
3
4
<?
echo "The alexa rank for Google is :". Get_Alexa_Rank('google.com') ."<BR>";
echo "The alexa rank for blogger is :". Get_Alexa_Rank('blogger.com') ."<BR>";
?>

Now at this post time I got this result:
The alexa rank for Google is :1
The alexa rank for blogger is :65


If this post was good and helpful for you, Please give it Like.
.

1 comments: