PHP Code to Get Alexa Rank

By | September 2, 2012

Every website have an unique alexa rank. To see the alexa rank of our site, we have to go to the or install alexa plugin or place alexa widget in our website. By using php code also we can get alexa rank for our website. Here i have used php code to get alexa rank. In this , alexa rank and its associated details for the provided website will be displayed. preg_match() php function will be used to get the alexa rank from the page source.

Using preg_match() php function, <popularity> will be find of  from the page and stored in $alexa array variable.

$alexa[1] – This will result URL, which we provided.

$alexa[2] – This array varialble will store alexa rank.

[code type=php]

<form action=”” method=”post”>
Enter Your Website: <input type=”text” name=”url” />
<input type=”submit” name=”submit” />
$url1 = file_get_contents(‘’.$url);
preg_match(‘/<popularity url=”(.*?)” text=”([0-9]+)” source=”panel”\/>/si’, $url1, $alexa);
$rank = ($alexa[2]) ? $alexa[2] : 0;
echo $rank;


2 thoughts on “PHP Code to Get Alexa Rank

Leave a Reply

Your email address will not be published. Required fields are marked *