Collecting del.icio.us Tags in PHP

Our second PHP script, getDeliciousTags.php, produces a list of tags from themost recent entries in your del.icio.us account. If you don't have a del.icio.usaccount, you can either get one (it's free) or use my username (jbum) as I'm doingin these examples. You can view my del.icio.us bookmarks at the following URL: http://del.icio.us/jbum .

Del.icio.us provides tags in an RSS feed. To collect and parse the RSS data, we'lluse the library magpie RSS, a freely available RSS parser for PHP. You candownload magpie at: http://magpierss.sourceforge.net/

You will need to follow the instructions that come with magpie RSS to install it onyour server.

Because this script deals with RSS data, it looks a bit different than the previousscript. Let's examine it in detail:

<?
//
// Collect delicious tags (or load them from a cache)

function getTags()
{
  global $tags;

Again, the script contains a single function, getTags(), which is responsible forbuilding up the global associative array, $tags.

 // use the parameter 'who' to determine which account to poll
 // it defaults to 'jbum'

 $who = 'jbum';
 if (isset($_GET['who']))
   $who = $_GET['who'];

The previous lines determine which del.icio.us account you are collecting tags for.If one is specified in the URL parameters, it will be used, otherwise, my account,'jbum' will be used.

 // remove troublesome characters from name
 $who = preg_replace('/\W/', '',$who);

Since this script is intended to be used on a web site, we have ...

Get Building Tag Clouds in Perl and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.