Page 1 of 1
Forum

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 no translation for that post!



PHP: Simple PHP scr...
 
Share:
Notifications
Clear all

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

1 Posts
1 Users
0 Likes
1,325 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2676
Topic starter  

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;
}

   
ReplyQuote
Share: