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!
[Solved] PHP: Simple PHP script to retrieve the Alexa Ranking of your website
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
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('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;
}