How to get the Alexa rank from PHP?

Discussion in 'PHP' started by q7m, Sep 23, 2009.

  1. #1
    I need a php function to return the Alexa rank of a given domain.

    I know that there are lots of these on the web (I have successfully used some of them until now), but recently Alexa changed something on theirs system and the existing functions doesn't seem to work anymore. Please indicate me one that you have recently used and it works.

    Thanks to all!
     
    q7m, Sep 23, 2009 IP
  2. rishi

    rishi Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Does Alexa provide an API for users?
     
    rishi, Sep 23, 2009 IP
  3. phprightnow

    phprightnow Peon

    Messages:
    296
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm not sure if they provide an API, but here's how to do it by just grabbing the page...

    <?php
    $domain = "phpright.com"; // Change this to your domain
    $file = file_get_contents("http://www.alexa.com/siteinfo/".$domain);
    $file = strstr($file,'alt="Global"');
    $file = substr(strstr($file,'>'),1);
    $file = str_replace(strstr($file,'</a>'),'',$file);
    $file = trim($file);
    echo 'Your ranking: '.$file;
    ?>
    PHP:
     
    phprightnow, Sep 23, 2009 IP
  4. pneulameiro

    pneulameiro Peon

    Messages:
    440
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    very useful phprightnow! Thanks. I was searching for this script too.
     
    pneulameiro, Sep 23, 2009 IP
  5. Justin_Timberlake

    Justin_Timberlake Guest

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks dude!
     
    Justin_Timberlake, Sep 23, 2009 IP
  6. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thats pretty slick, thanks.
     
    pixmania, Sep 24, 2009 IP