PHP uses Alexa API to get the website Alexa ranking Example _php tutorial

Source: Internet
Author: User
Tags xml parser
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.