Skip to content

Instantly share code, notes, and snippets.

@SheriSmith
Last active January 8, 2021 06:50
Show Gist options
  • Save SheriSmith/d91a2f57a51d599ce8f835e1b9ce358b to your computer and use it in GitHub Desktop.
Save SheriSmith/d91a2f57a51d599ce8f835e1b9ce358b to your computer and use it in GitHub Desktop.
<?php
$source = file_get_contents('http://data.alexa.com/data?cli=10&dat=snbamz&url=yourdomain.com');
//Alexa Rank
preg_match('/\<popularity url\="(.*?)" text\="([0-9]+)" source\="panel"\/\>/si', $source, $matches);
$aresult = ($matches[2]) ? $matches[2] : 0;
//Alexa Sites Linking in
preg_match('/\<linksin num\="([0-9]+)"\/\>/si', $source, $asli);
$alinksin = ($asli[1]) ? $asli[1] : 0;
//Alexa US Rank
preg_match('/\<country code\="US" name\="United States" rank\="([0-9]+)"\/\>/si', $source, $rankus);
$usrank = ($rankus[1]) ? $rankus[1] : 0;
//Alexa Reach Rank
preg_match('/\<reach rank\="([0-9]+)"\/\>/si', $source, $reachr);
$areach = ($reachr[1]) ? $reachr[1] : 0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="NOINDEX, NOFOLLOW" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Alexa Rankings</title>
<style type="text/css" media="screen">
body {background-color: #999; font-family: Arial, sans-serif; color: #004C9C;}
h1 {text-align: center;}
table {width: 50%; margin: 0 auto; font-size: 14pt;}
tr {line-height: 2;}
td {padding-left: 5px;}
#outer {width: 100%;}
#inner {width: 50%; margin: 0 auto; background-color: white; padding: 50px; border: 1px solid #333;}
.blue {background: #E6ECF2;}
.yellow {background: #FFFF99; }
</style>
</head>
<body>
<div id="outer">
<div id="inner">
<h1>Alexa Rankings</h1>
<table>
<tr class="blue">
<td>Alexa Global Rank:</td>
<td><strong><?php echo $aresult; ?></strong></td>
</tr>
<tr class="yellow">
<td>Alexa Sites Linking In:</td>
<td><strong><?php echo $alinksin; ?></strong></td>
</tr>
<tr class="blue">
<td>Alexa U.S. Rank:</td>
<td><strong><?php echo $usrank; ?></strong></td>
</tr>
<tr class="yellow">
<td>Alexa Reach Rank:</td>
<td><strong><?php echo $areach; ?></strong></td>
</tr>
</table>
</div>
</div>
</body>
</html>
@ali-chegini
Copy link

This code does not run on the server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment