PHP: Process Technorati API
Processing the Technorati API allows you to receive information about your blog and rankings logged with the Technorati service. An example of extracting various pieces of information is here
$url = "www.yourchosendomain.com";
$apikey = "putyourapikeyhere";
$service = "http://api.technorati.com/bloginfo?key=" . $apikey . "&url=" .urlencode($url);
// call the service and get results
$xmlresult = file_get_contents($service);
// results found?
if ($xmlresult === false)
{ die("Unable to process request"); }
// attempt to process xml
$error = null;
if (!$dom = domxml_open_mem($xmlresult, DOMXML_LOAD_PARSING ))
{ die("Unable to parse XML"); }
else
{
echo get_details( $dom,"name" );
echo get_details( $dom,"url" );
echo get_details( $dom,"inboundblogs" );
echo get_details( $dom,"rank" );
}
// search elements until target tag found
function get_details( $dom,$searchtag )
{
$root = $dom->document_element();
$node = $root->first_child();
$myitem = $root->get_elements_by_tagname($searchtag);
// loop through elements
for($i=0;$i { echo "<p>" . $searchtag . " is [" . $myitem[$i]->get_content() . "]</p>"; }
}
?>
Submit a Comment