alexa-internet

How to get country wise alexa rank of a website using php?


I want to get country wise alexa ranking of a specific website using PHP or JAVASCRIPT.

Can anyone help me?


Solution

  • <?php
        $url='google.com.sg';
        $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;
        $country_rank=isset($xml->SD[1]->COUNTRY)?$xml->SD[1]->COUNTRY->attributes()->RANK:0;
        $web=(string)$xml->SD[0]->attributes()->HOST;
        echo $web." has Alexa Rank ".$rank." and Country Rank ".$country_rank.".\n";
    ?>
    

    The result will be

    google.com.sg has Alexa Rank 282 and Country Rank 2.

    Adapted from here