We usually use Alexa’s website (or other webmaster tool websites) to check our website traffic ranking, so you must go to those websites. In fact, you can obtain the Alexa-related data (in XML format) of the website through the Alexa XML API, and then use an XML parser to parse the XML returned by Alexa to obtain 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 by http://data.alexa.com/data?cli=10&dat=snbamz&url=jb51.net is as follows:
Copy code The code is as follows:
The value of the TEXT attribute in the POPULARITY element is 7552101 It’s Alexa ranking.
Code implementation:
The code to use PHP to obtain Alexa ranking through Alexa API is:
Copy the code The code is as follows:
< php>
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); 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"];
}
}
}
}
?> ;
Usage:
Copy code
The code is as follows: echo getAlexaRank("jb51.net");
?>
http://www.bkjia.com/PHPjc/788629.html
www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/788629.htmlTechArticleWe usually use Alexa’s website (or other webmaster tool websites) to check our website traffic ranking. So you have to go to those websites. In fact, you can get the website's... through the Alexa XML API