Latest Alexa Ranking

Discussion in 'PHP' started by blue-eye, Mar 20, 2010.

  1. #1
    Hi,

    I want to show latest alexa ranking of multiple sites on my website. For example like this

    www-example-com 202021
    www-example1-com 102343
    www-example2-com 10234324

    I need to use PHP code for this purpose. Can any body help in this regards.
     
    blue-eye, Mar 20, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    koko5, Mar 20, 2010 IP
  3. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #3
    	// Find your alexa ranking
    	public 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 $str[1];
    	}
    
    PHP:
    Source: http://abcoder.com/php/get-google-page-rank-and-alexa-rank-of-a-domain-using-php/
     
    Alex Roxon, Mar 20, 2010 IP
  4. Latox

    Latox Active Member

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    96
    #4
    Just for future reference, if there isn't an API available for another site in future, you could always use file_get_contents and regular expressions to get the information you need.
     
    Latox, Mar 20, 2010 IP