NeoArch

What's past is prologue; what's present is weblog

Learning PHP–the practice, not the book

with 2 comments

I am currently learning php by reading the book that I am currently reviewing entitled Learning PHP5. At the same time, I have recently run into a problem because I needed to convert RSS into OPML and I did not know how. Tonight, I was elated when I was able to modify a php script found here to allow me to create the nice blogroll that you see on the sidebar of this blog. WordPress allows you to upload OPML files, but I can only generate an RSS feed with my account at del.icio.us. This script allows you to generate OPML from an RSS feed using php. Sweet. Changing the script to suit my needs was a good lesson in php editing. I also had to install MagpieRSS to get the script to run. I feel like a major genius now. I had created simple php documents before, but this was much different. I know this edit is probably simple, but it was a major accomplishment for me.

Below is what the script looks like after I tweaked it. It should be able to produce OPML that can be used on an iPod or in WordPress. I would have put it in red or something, but because of security reasons, wordpress.com does not like people to use in-line styles, nor do they support the ruby element. Anyway, here it is.

< ?php

$username = "birdsnare" ;
$tag = "library" ;

header('Content-Type: text/xml') ;
require_once('magpierss/rss_fetch.inc');

$url = "http://del.icio.us/rss/$username/$tag/";
$rss = fetch_rss($url);

// print_r($rss) ;
$items = $rss->items ;
?>
<opml version="1.1">
<head>
<title>del.icio.us list2OPML: < ?= $username ?>/< ?= $tag ?></title>

<link>http://del.icio.us/&lt; ?= $username ?>/< ?= $tag ?></link>
<ttl>3600</ttl>
</head>

<body>
<outline text="del.icio.us 2 OPML">
< ?php
for($i=0; $i<count($items); $i++) {
echo "\t\t\t<outline title=\"{$items[$i]['title']}\" text=\"{$items[$i]['title']}\" type=\"rss\" htmlUrl=\"{$items[$i]['link']}\" xmlUrl=\"{$items[$i]['link']}\"/> \n" ;

}
?>
</outline>
</body>
</opml>

Click here to see the output.

Hint--If you use this script, make sure you remove the whitespace between the less than sign and the question mark in the two beginning php tags in the script. Enjoy.

Technorati Tags:

About these ads

Written by Jason Fowler

February 4, 2006 at 2:45 am

Posted in Archives, Systems

2 Responses

Subscribe to comments with RSS.

  1. Thank you for posting this information, including your edit on this script, here. Someone on the OPML Editor support list directed me to your post, as I’m currently looking for a way to convert some RSS documents to OPML. Congrats on your PHP skillz-buildin’, too — I’m currently learning Ruby using a few resources, including the free “Why’s (Poignant) Guide to Ruby” and the brand-spankin’ new “Ruby Cookbook”, so I can relate…

    Harold J. Johnson

    August 8, 2006 at 3:54 pm

  2. Here’s a Perl script that I wrote to do the same kind of thing:

    http://kartiksubbarao.com/exporting-delicious-blog-links-to-opml

    Kartik Subbarao

    July 13, 2009 at 4:32 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 887 other followers