<?php echo '<?xml version="1.0" standalone="yes" encoding="UTF-8"?'.'>' ?>

<tags>
<?php 

//error_reporting(E_ALL);
//Error reporting? I have no errors! ... erm... not now, at least.

if (!extension_loaded("sqlite"))
{
        dl("sqlite.so");
}

// I really should do something with $err
if ($db = sqlite_open("/tmp/bookmarks.sqlite", 0666, $err))
{
	$tags = array();
	$prevtags = array();
	
        $result = sqlite_query ($db, "SELECT keywords FROM bookmarks");
        while (sqlite_has_more($result))
        {
                $foo = sqlite_fetch_array ($result);
		$thistag = split(" ", $foo['keywords']);
		// print_r(array) is worth remembering.
		$prevtags = array_merge($tags);
		$tags = array_merge($prevtags, $thistag);
        }
	natcasesort($tags);
	$uniq=array_unique($tags);
	$count=array_count_values($tags);
        foreach ($uniq as $tag)
        {
		if ($tag != '')
		{
			$c = $count[$tag];
                	print "<tag count='$c' tag='".trim($tag)."' />";
			printf("\n");
		}
        }
}
?>		
</tags>

