We will use the Alexa website (or other webmaster Tools website) to check our website traffic rankings, so we must go to those sites. In fact, the Alexa XML API can be used to obtain the Web site Alexa-related data (XML format), and then use the XML parser to parse the Alexa returned XML, get Alexa rankings or other data.
Alexa Interface
Alexa's XML API interface is: http://data.alexa.com/data?cli=10&url=%YOUR_URL%
If you want to get more data, you can use: http://data.alexa.com/data?cli=10&dat=snbamz&url=%YOUR_URL%
The data returned with Http://data.alexa.com/data?cli=10&dat=snbamz&url=jb51.net is as follows:
Copy the Code code as follows:
The value 7552101 of the Text property in the popularity element is the Alexa rank.
Code implementation:
The code for getting Alexa rankings by using the Alexa API in PHP is:
Copy the Code code as follows:
function Getalexarank ($Domain) {
$line = "";
$data = "";
$URL = "Http://data.alexa.com/data/?cli=10&dat=snba&url=". $Domain;
$fp = fopen ($URL, "R");
if ($fp) {
while (!feof ($fp)) {
$line = fgets ($FP);
$data. = $line;
}
$p = Xml_parser_create ();
Xml_parse_into_struct ($p, $data, $vals);
Xml_parser_free ($p);
for ($i =0; $i
if ($vals [$i] ["tag"]== "popularity") {
return $vals [$i] ["Attributes"] ["TEXT"];
}
}
}
}
?>
How to use:
Copy the Code code as follows:
Echo Getalexarank ("jb51.net");
?>
http://www.bkjia.com/PHPjc/788629.html www.bkjia.com true http://www.bkjia.com/PHPjc/788629.html techarticle We will use the Alexa website (or other webmaster Tools website) to check our website traffic rankings, so we must go to those sites. In fact, you can get the Web site by the Alexa XML API ...