Home >Backend Development >PHP Tutorial >PHP uses Alexa API to get the Alexa ranking of the website Example_PHP Tutorial

PHP uses Alexa API to get the Alexa ranking of the website Example_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:25914browse

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

http: //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
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP database universal engine class adodb configuration usage and example collection_PHP tutorialNext article:PHP database universal engine class adodb configuration usage and example collection_PHP tutorial

Related articles

See more