There is nice wordpress plugin which will help you to add alexa rank in your website. In this article, we briefly explained to get alexa rank using php code
get alexa rank using php code
if you want to check the your website ranking as per alexa so you can use the following code in your php projects. There is very nice wordpress plugin which will help you to add the alexa rank in wordpress site. In this article I given PHP code for adding the alexa rank block on any website.
Alexa Rank Widget
http://data.alexa.com/data?cli=10&dat=s&url=wordpressapi
“http://data.alexa.com/data” this file will return the xml format output. Using the XML output or reading xml file we can easily fetch the our or any website ranking.
Use the following function for getting the alexa website ranking.
<?php function AlexaRank( $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; } echo "purabtech.in/files/ Rank as per alexa.com: "; echo AlexaRank('purabtech.in/files/'); ?>
if you want to check the multiple website ranking in one shot than use the following PHP code.
<?php $domains = array( 'google.com', 'ask.com', 'yahoo.com', 'bing.com' ); foreach ( $domains as $domain ) echo $domain, ' - ', AlexaRank( $domain ), '<br />', PHP_EOL; ?>
Have fun!
A great code.. i really need it… thx 🙂
Thank you. I was looking for a similar code to evaluate by batch a list of sites.
I still have some problem in configuring my server.
There is an error
file_get_contents(http://data.alexa.com/data?cli=10&dat=s&url=google.com) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in ###
Did you have similar problems ?
It works for me only 1 time. I repeat domains in loop, and script always return me 0 🙁
Very useful and interesting article for we developers who want to develop alexa rank checker.
Just wish to say your article is as astonishing.
The clarity in your post is simply excellent
and i could assume you’re an expert on this
subject. Well with your permission let me to grab your feed to keep up to date with forthcoming post.
Thanks a million and please continue the
gratifying work.