Monday, July 21, 2014

Display alexa rank in your website using php

This is very simple php scipt,it is used to display your website alexa rank in website.


Live DemoDownload Script


Replace url="your website url".
file_get_contents is used to read a file into a string.

Php alexa rank Code

<?php $url = file_get_contents('http://data.alexa.com/data?cli=10&dat=snbamz&url=http://codeinnovators.blogspot.in/'); ?>

Full Source Code

<?php

        $url = file_get_contents('http://data.alexa.com/data?cli=10&dat=snbamz&url=http://codeinnovators.blogspot.in/');
      
        //Alexa Rank
        preg_match('/\<popularity url\="(.*?)" text\="([0-9]+)" source\="panel"\/\>/si', $url, $matches);
        $globalrank = ($matches[2]) ? $matches[2] : 0;
       
        //Alexa Sites Linking in
        preg_match('/\<linksin num\="([0-9]+)"\/\>/si', $url, $cocok);
        $alexabacklinks = ($cocok[1]) ? $cocok[1] : 0;
       
        echo "Global Rank : ".$globalrank;
        echo "<br>";
        echo "Alexa Backlinks : ".$alexabacklinks;
        ?>
 
Please share your comments and feedback.Thanks.Please subscribe my updates via email.

1 comment: