Page 1 of 1

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.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!

Clear all

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


Noble Member Admin
Joined: 7 years ago
Posts: 1298
August 18, 2015 3:14 AM  

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(''); // for plain HTML or other CMS systems
funcion GetAlexaRank($url)
    $xml = simplexml_load_file("".$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;