Return to Snippet

Revision: 67774
at October 29, 2014 08:50 by codingforever99


Initial Code
<?
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;
}


//example:
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>";
 
?>

Initial URL
http://function-code.blogspot.com/2014/10/get-alexa-rank-using-php.html

Initial Description
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.

Initial Title
Get alexa rank using php

Initial Tags
php

Initial Language
PHP