O'Reilly logo

Building Tag Clouds in Perl and PHP by Jim Bumgardner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required