Code PHP để check alexa rank
by saosangmo on Dec.07, 2007, under Nice Scripts
<?php
function alexaRank($domain)
{
$ch = curl_init(‘http://alexa.com/data/details/traffic_details?url=’.$domain);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1″);
$curl_ret = curl_exec($ch);
curl_close($ch);
$curl_ret = explode(‘Visit http://aws.amazon.com/awis for more information about the Alexa Web Information Service.–>’, $curl_ret);
$curl_ret = array_shift(explode(‘<br’,$curl_ret[1]));
$ret = ”;
$ignore = false;
for($i=0;$i<strlen($curl_ret);$i++)
{
if ( is_numeric($curl_ret{$i}) && !$ignore )
$ret .= $curl_ret{$i};
else if ( $curl_ret{$i} == ‘<’ )
$ignore = true;
else if ( $curl_ret{$i} == ‘>’ )
$ignore = false;
}
return (int)$ret;
}
?>
Để sử dụng, chúng ta có thể gọi nó dạng như sau:
echo alexaRank(‘webdigity.com’);
