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

WBOY
Release: 2016-07-13 10:28:25
Original
870 people have browsed it

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
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!