Alexa Ranking Script

2008 May 13
tags: ,
by George

I was looking around online, and I couldn’t see a free Alexa ranking script, I was actually looking for one for my plugin. So, I decided that (with a little help from the Alexa developer site thing, and from another website) that I’d throw one together (I’m getting pretty good at this :evilgrin: ) and make it available.

I’m going to do it using a function, because it seems easier to me. We’ll make a function that checks and returns the Alexa rank in plain numbers for any given site.

<?php function findmyalexarank($site) {
$dataurl = "http://data.alexa.com/data?cli=10&dat=snbamz&url=".$site;
$process = simplexml_load_file($dataurl) or die("ugh, something went wrong");
echo $process->SD->POPULARITY['TEXT'];
}
?>

The above means that when you call the function with your URL, it’ll return something similar to 600455.

You call it like this:

<?php
findmyalexarank("http://www.gpearce.co.uk");
?>

Which returns 859044 or similar. Stick some text either side, and you could graft it into your template. Note - I didn’t write all of this, I just modified some existing code quite a bit ;P

No Comments

Leave A Comment

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS