1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

alexa ranking

Discussion in 'PHP' started by mavicin, Aug 13, 2005.

  1. #1
    how can i find alexa ranking php code
     
    mavicin, Aug 13, 2005 IP
  2. Crazy_Rob

    Crazy_Rob I seen't it!

    Messages:
    13,157
    Likes Received:
    1,366
    Best Answers:
    0
    Trophy Points:
    360
    #2
    I believe you need to use the Amazon API.
     
    Crazy_Rob, Aug 13, 2005 IP
  3. mavicin

    mavicin Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i 've got amazon api but how can i do this :eek:
     
    mavicin, Aug 13, 2005 IP
  4. Smyrl

    Smyrl Tomato Republic Staff

    Messages:
    13,740
    Likes Received:
    1,702
    Best Answers:
    78
    Trophy Points:
    510
    #4
    If all you are trying to do is show Alexa rank or whatever they call it, there is a link on the Alexa site where you get the code. Look around.

    ----------

    I went to Alexa and had a look around myself. They have a section called webmaster tools. The needed link there is not currently working for me.

    Shannon
     
    Smyrl, Aug 13, 2005 IP
  5. Crazy_Rob

    Crazy_Rob I seen't it!

    Messages:
    13,157
    Likes Received:
    1,366
    Best Answers:
    0
    Trophy Points:
    360
    #5
    I've never done it myself but I found these steps on another forum.

     
    Crazy_Rob, Aug 13, 2005 IP
  6. mavicin

    mavicin Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    http://forum.checkurl.info/index.php?showtopic=19
    i found this code but it doesnt work:(
     
    mavicin, Aug 13, 2005 IP
  7. Crazy_Rob

    Crazy_Rob I seen't it!

    Messages:
    13,157
    Likes Received:
    1,366
    Best Answers:
    0
    Trophy Points:
    360
  8. Shoemoney

    Shoemoney $

    Messages:
    4,474
    Likes Received:
    588
    Best Answers:
    0
    Trophy Points:
    295
    #8
    paste your code... that works for me
     
    Shoemoney, Aug 13, 2005 IP
  9. shacow

    shacow Active Member

    Messages:
    339
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #9
    shacow, Jan 11, 2009 IP
  10. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #10
    Nice untruths...

    function getAlexaRank( $url )
    {
        preg_match( '#<POPULARITY URL="(.*?)" TEXT="([0-9]+){1,}"/>#si', file_get_contents('http://data.alexa.com/data?cli=10&dat=s&url=' . $url), $p );
        return ( $p[2] ) ? number_format( intval($p[2]) ):0;
    }
    
    $domains = array( 'google.com', 'danltn.com', 'msn.com', 'live.com' );
    
    foreach ( $domains as $domain )
        echo $domain, ' - ', getAlexaRank( $domain ), '<br />', PHP_EOL;
    PHP:
    Works just fine for me.
     
    Danltn, Jan 11, 2009 IP
    q7m likes this.
  11. shacow

    shacow Active Member

    Messages:
    339
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #11
    Yes, that is certainly better then scraping the site like in the previously posted link.
     
    shacow, Jan 11, 2009 IP
  12. blue-eye

    blue-eye Greenhorn

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #12
    Is this code working? I want to show alexa ranking of multiple sites on my blog, will this code work? does anybody else have some better code?
     
    blue-eye, Mar 20, 2010 IP
  13. Latox

    Latox Active Member

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    96
    #13
    
    <?php
    function Alexa($domain)
        {
            $remote_url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url='.trim($domain);
            $search_for = '<POPULARITY URL';
    
            if ($handle = @fopen($remote_url, "r")) 
            {
                $part = null;
    
                while (!feof($handle))
                {
                    $part .= fread($handle, 100);
                    $pos = strpos($part, $search_for);
                    if ($pos === false)
                        continue;
                    else
                        break;
                }
    
                $part .= fread($handle, 100);
                fclose($handle);
            }
    
            $str = explode($search_for, $part);
            $str = array_shift(explode('"/>', $str[1]));
            $str = explode('TEXT="', $str);
            return number_format($str[1]);
        }
    
    echo "Alexa ranking: " . Alexa("http://www.digitalpoint.com"); //Output: Alexa ranking: 186
    ?>
    
    PHP:
    Function above should do what you need.
     
    Latox, Mar 20, 2010 IP
  14. bytechip

    bytechip Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    <?php
    $url = ‘bytechip.com’;
    $new_url = ‘http://www.alexa.com/siteinfo/’.$url;
    $contents=file_get_contents($new_url);
    
    /* This will find the Global Alexa Rank */
    $start = strpos($contents, “<div class=\”data up\”>”) +119;
    $stop= strpos($contents,”<div class=\”label\”>Alexa Traffic Rank”);
    $result = substr($contents,$start,$stop-$start);
    echo “Global Alexa Rank for “.$url.” = “.$result;
    ?>
    Code (markup):
    For more information : Check out http://www.bytechip.com/2010/04/get-alexa-rank-using-php/
     
    bytechip, Apr 24, 2010 IP