FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Fetch Alexa Rank of website using PHP function easily





ankurthakur
Hello Guyz,

I have made this small PHP Function which will let you fetch website's Alexa Rank easily using php only.

You can read more about this here : http://ankurthakur.in/forum/viewthread.php?thread_id=90

Here is the function :
Code:
<?php
 
function get_alexa_rank($domain)
{
   // The URL to XML Data
   $xmldata = file_get_contents("http://xml.alexa.com/data?cli=10&url=".$domain);
 
   // Initialising variable
   $rank = 0;
 
   if (!$xmldata)
   {
      return $rank;
   }
   else
   {
      if (preg_match('/\<POPULARITY URL\="(.*)" TEXT\="([0-9]+)"\/\>/s',$xmldata,$matches))
      {
         $rank = $matches[2];
      }
      return $rank;
   }
}
 
echo "Alexa Rank of ankurthakur.in is ".number_format(get_alexa_rank("ankurthakur.in"));
 
?>


I hope that this will be helpful to some people.

Thank You

Regards,
Ankur Thakur
ogah
i use this
Code:

<?php
$source = file_get_contents('http://data.alexa.com/data?cli=10&dat=snbamz&url=yourdomain.com');
preg_match('/\<popularity url\="(.*?)" text\="([0-9]+)"\/\>/si', $source, $matches);
$result = ($matches[2]) ? $matches[2] : 0;
preg_match('/\<linksin num\="([0-9]+)"\/\>/si', $source, $cocok);
$linksin = ($cocok[1])?$cocok[1]:0;
echo 'Alexa Rank yourdomain.com: <a href="http://www.alexa.com/siteinfo/yourdomain.com">'.number_format($result).'</a>';
if($linksin != NULL){ echo '<br/>Links In : <a href="http://www.alexa.com/site/linksin/yourdomain.com">'.number_format($linksin).'</a>'; }
?>
D'Artagnan
hey, nice tutorial, i'm just wondering why don't you guys use PHP built in XML parsers?
http://www.kirupa.com/web/xml_php_parse_beginner.htm
nextime
ankurthakur wrote:
Hello Guyz,

I have made this small PHP Function which will let you fetch website's Alexa Rank easily using php only.

You can read more about this here : http://ankurthakur.in/forum/viewthread.php?thread_id=90

Here is the function :
Code:
<?php
 
function get_alexa_rank($domain)
{
 // The URL to XML Data
 $xmldata = file_get_contents("http://xml.alexa.com/data?cli=10&url=".$domain);
 
 // Initialising variable
 $rank = 0;
 
 if (!$xmldata)
 {
  return $rank;
 }
 else
 {
  if (preg_match('/\<POPULARITY URL\="(.*)" TEXT\="([0-9]+)"\/\>/s',$xmldata,$matches))
  {
   $rank = $matches[2];
  }
  return $rank;
 }
}
 
echo "Alexa Rank of ankurthakur.in is ".number_format(get_alexa_rank("ankurthakur.in"));
 
?>


I hope that this will be helpful to some people.

Thank You

Regards,
Ankur Thakur

very helpful thanks very much i will save this code.
Related topics
[tutor] How to protect images without htaccess using PHP
Using PHP
Help with PHP
Includ Images using PHP.
How to start using PHP? Help!
A very good PHP MySQL Tutorial
Website Designing using PHP
how can i setup a page break for printer on html using php ?
I am trying to build a contact form using php and flash
Using php to change content of a .txt
Making a expression calculator using PHP.
Email Using PHP
i want to dezign a website using php
Sample website using PHP and mySQL in Linux environment
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.