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?
Thanks for your code…Its really helpful for every one around the world..
Thanks for the positive response:) I hope it helps some lost souls out there:)
Wow your like a Php god! you wouldn’t believe how long I’ve spent trying to find out how to do this and you whip it up in 7 lines of php!
Its really helped me to build my site…thanks
Thanks for this great script. It works flawlessly.
Oh, thanx a lot man, this really helps.
Nice post..really gift to every one
keep going…..:)
great help, thanks.
you can reach me at latent_tm@yahoo.com