I'm trying to receive information about Alexa Top Sites from a Contrie, and i would like to receive:
For the URL i'm getting already, but when i add tag for website position something isnt working, here's my code:
<?php
for ($z=0;$z<2;$z++) {
$html=file_get_contents('http://www.alexa.com/topsites/countries;'.$z.'/PT');
preg_match_all(
'/<div class="count">.*?<\/div>.*?<a href="\/siteinfo\/.*?">(.*?)<\/a>/s',
$html,
$array, //array with sites
PREG_SET_ORDER
);
for ($i=1;$i<count($array);$i++) {
echo "<pre>"; print_r($array); echo "</pre>";
}
}
?>
I'm getting this:
Array
(
[0] => Array
(
[0] =>
1
google.pt
[1] => google.pt
)
[1] => Array
(
[0] =>
2
Why not use the official API?
It costs $0.15 for 1,000 requests, and you''ll get nice XML readble by SimpleXML. As bonus - you won't violate the alexa terms of usage.
To get an Alexa rank of a website using PHP you can use the following code:
<?
$url="http://theurl.com";
$xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$url);
$rank=isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
$web=(string)$xml->SD[0]->attributes()->HOST;
echo $web." has an alexa rank of: ".$rank;
?>
Hope that helps
source - http://99webtools.com/php-script-to-get-alexa-rank.php
Check this out...will help you..
http://www.phpclasses.org/package/4873-PHP-Get-site-ranking-information-from-Alexa-site.html
You can try following code:
function getAlexaRank($domain) {
$request = "http://data.alexa.com/data?cli=10&dat=s&url=" . $domain;
$data = getPageData($request);
preg_match("/<POPULARITY URL="(.*?)" TEXT="([\d]+)"/si", $data, $p);
$value = ($p[2]) ? number_format($p[2]) : "n/a";
$string = "<a href=\"http://www.alexa.com/siteinfo/" . $domain . "\">" . $value . "</a>";
return $string;
}
echo 'Rank: '.getAlexaLinks('www.your-domain.com'); // returns Rank: 118
Hope helps you
source: http://w3webtools.com/php-code-get-alexa-rank-and-site-linking/
</div>