Learning PHP–the practice, not the book
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/< ?= $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:

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…
Comment by Harold J. Johnson — August 8, 2006 @ 3:54 pm