Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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

This comment has been minimized.

Copy link

@ali-chegini ali-chegini commented Jun 1, 2019

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