Tuesday, May 11, 2010

1:02 AM

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

//enter the blog url don't include http
//seeting the URL for technorati
//get the html code of the 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
//geting the the rank values out of the string
//Display the rank.
echo "Technorati rank is : ".$matches[0];

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.