get alexa rank using php code

get alexa rank using php code

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;

?>
get alexa rank using php code
get alexa rank using php code

Have fun!

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

5 thoughts on “get alexa rank using php code”

  1. 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.

Leave a Reply to Andrew Cancel reply

Your email address will not be published.