PHP, RSS and del.icio.us
Things to remember when doing dumb things like moving your site to PHP just to get a cool RSS feed:
- XML declarations in XHTML 1.1
-
Loons like me who set up with an XHTML 1.1 DOCTYPE declaration also need an appropriate XML declaration at the start of the document too:
<?xml version="1.0" charset="UTF-8"?>
Putting this into a PHP file causes the server to blindly assume that that must be PHP code and (duh) falls over at the first hurdle. There seems to be a multitude of ways around this, but the one that worked for me was the simplest:
<?php echo "<?xml version=\"1.0\" charset=\"UTF-8\"?>
- Fixing broken URL's for extinct .html pages
-
At first, I toyed with the idea of some rules in the httpd.conf file but frankly I couldn't be arsed.
In the event, I wrote a custom 404 ErrorDocument that looks at the REQUEST_URI, has a look to see if it's got the word "archives" in it, and if so, do a quick search and replace job on it. Something like:
if (strstr($REQUEST_URI, archives)) {
$oldpage = $REQUEST_URI;
$newpage = ereg_replace(".html", ".php", $oldpage);
}If I were I being a good person, I’d check the local file system for the presence of the document, but in this instance, I know the documents are there for sure and so I don't really care too much.
- Escaping URL's from del.icio.us feeds
-
And just as you think it's all wrapped up... the W3C Validator decided to have a jolly good moan about the occasional URL I was pulling in from the del.icio.us RSS feed that had unescaped ampersands in it. Again, PHP and regex functions sorted that one out (I'm using the excellent Magpie RSS to take care of parsing the feeds otherwise):
$href = ereg_replace("&", "&", $item['link']);