I’ve just put up this blog, so, my technorati ranks are not as good as they were.

In order to control them, I wrote a small PHP script to write the current date and my rank into a file, appending my rank to that same file every time the script is used.

I’ll share it here, it might be helpful for someone!

<?php

/* This script is intended to get your rank from technorati
* and save it with the current date into a file.
*
* This is just meant for someone who wants to learn php or
* anyone who wants to keep track of their technorati rank.
*
* The call is made using a REST-ful interface.
* Send either a HTTP GET or a HTTP POST to
* http://api.technorati.com/bloginfo?key=[apikey]&url=[blog url]
* with mandatory parameters “key” and “url” and one optional
* parameter to request various formats.
*
* You’re free to change it in whatever way you want to.
* Please keep the credits.
*
* Tiago Boldt Sousa
* http://blog.tiagoboldt.net
*/

//Change this to any data
$mykey=”APIKEY”; //Get your technorati api key, and put it in there
$myblog=”http://blog.tiagoboldt.net”;//Change it for your blog
$filename=”technoratiranks.txt”;//Rename the file if you want to

//Creating the URL
$techurl=”http://api.technorati.com/bloginfo”;
$myurl=$techurl .”?” . “key=” . $mykey . “&url=” . $myblog;

//Opening the URL
$fp=fopen($myurl,”r”) or die(“Not connecting”);
$data=stream_get_contents($fp);
fclose($fp);

//Parse the XML into arrays
$parser=xml_parser_create();
xml_parse_into_struct($parser,$data,$values,$index);
xml_parser_free($parser);

//Get your RANK from the XML
$myrank=($values[$index[“RANK”][0]][“value”]) or die (“Impossible to get your rank”);

//Write your current rank into a file
$fp=fopen($filename,”a”) or die(“Unable to create or write the file”);
fwrite($fp,date(“F d, Y”).” Rank:”. $myrank.”\n”);
fclose($fp);

?>

Tags: ,