Categories

Archives

Syndication


Alexa ranking script

15
Sep
Posted at 5:26 pm in PHP, Programming

There are plenty of people out there searching for a script to get the alexa ranking for a site. Last time I looked I didn’t even find a free function to get the data, just some expensive solutions.

So anyway, here’s a PHP coded function we have made that collects the alexa-data with the SimpleXML function. It’s very easily coded so everyone should understand what it does. However, since it uses the SimpleXML function, it can only be used if you run PHP5. That’s a requirement.

Please give us some credit if you use the function. A comment or anything will work!

1
2
3
4
5
6
7
8
9
10
<?php
 
function getalexa($url){
// cdsrc.com
$request_url = "http://data.alexa.com/data?cli=10&dat=snbamz&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
 
?>

And here’s a little description of how to use it:

11
12
13
14
<?php
echo getalexa("http://cdsrc.com");
// This would print the alexaranking of cdsrc.com
?>

Simple huh?