Getting technorati ranking in PHP without using their API

Today, I was going through the Technorati API to find the rank of the blog using PHP. Those who doesn’t know about Technorati, Technorati is known as the authority for tracking, indexing and ranking the blog sytems. When I went through the Technorati Api, I found that it is not that hard to get the ranking of a blog which is indexed in Technorati.You need to get the developer API¬† key from Technorati and use their Web Services to get the ranking of a blog.

But, those who are not registered to the Technorati, here is the shortcut method to get the ranking of blogs indexed under Technorati without using their Api. I’ve used the following¬† URL of technorati

“http://www.technorati.com/blogs/<blog-url>”

and used some regular expression to find the ranking of the blog indexed under technorati withoug using their API.

PHP code to find the technorati ranking without using API

<?php
//enter the blog url don't include http
$blog_url="roshanbh.com.np";
//seeting the URL for technorati
$technorati_url="http://www.technorati.com/blogs/".$blog_url;
//get the html code of the URL
$html_values=file_get_contents($technorati_url);
//get the string within <div class="rank"></div>
preg_match("@<div\b[^>]* class=\"rank\">(.*?)</div>@si",$html_values,$matches);
//strip out of the HTML element from the matches
$rankvalue=strip_tags($matches[1]);
//geting the the rank values out of the string
preg_match("/(\d+(,\d+)?(,\d+)?)/",$rank_value,$matches);
//Display the rank.
echo "Technorati rank is : ".$matches[0];
?>

Download Source Code

As you can above, I’ve used file_get_contens() function of PHP to get the content from Technorati. The rank of the blog if found under the division “<div class=”rank”></div>” in that page of Technorati, you can verify it by viewing the source of that page. After that, I’ve used few regular expression to find the ranking of the blog in PHP.

One thing you must notice that this code will works under this design of Technorati, if the technorati will change the design then there is no guarantee that this code will work at that scenario.

2 thoughts on “Getting technorati ranking in PHP without using their API

  1. Sory for my English…

    I take u code, but my stats is bad… I have so Warning:

    file_get_contents(http://www.technorati.com/blogs/roshanbh.com.np) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /var/www/islelink/data/www/isle-blog.ru/wp-content/themes/default/page.php on line 160

    What is it – i don’t understand ??? :) Help me, pls, my stats heare: _http://isle-blog.ru/stats/

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>