Page 1 of 1

PHP: Simple PHP script to retrieve the Alexa Ranking of your website

PHP: Simple PHP script to retrieve the Alexa Ranking of your website

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.




RSS Feed

Home Forums Web Development PHP: Simple PHP script to retrieve the Alexa Ranking of your website

Tagged: , ,

This topic contains 0 replies, has 1 voice, and was last updated by  hans 3 years, 11 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • 4797

    hans
    Keymaster

    Below my simple PHP code to retrieve the Alexa page ranking of a given website …

    // Function: GetAlexaRank(websiteURL)
    // Returns Alexa ranking or 0 (zero)
    // Examples:
    // echo GetAlexaRank(get_bloginfo('name')); // for WordPress users
    // echo GetAlexaRank('www.mywebsite.nl'); // for plain HTML or other CMS systems
    funcion GetAlexaRank($url)
    {
        $xml = simplexml_load_file("http://data.alexa.com/data?cli=10&url=".$url);
        if(isset($xml->SD->POPULARITY)) { $alexa = $xml->SD->POPULARITY->attributes()->TEXT; } else { $alexa=0; }
        $alexa = echo number_format(floatval($alexa),0); // optional, for thousands
        return $alexa;
    }
Viewing 1 post (of 1 total)



You must be logged in to reply to this topic.