Tech Note: RSS Reader Rewritten

Technology • Views: 3,382

Our left-column Ajax RSS widget, with a drop-down list of news sites and blogs that lets you check out their current RSS feeds, has been completely rewritten. The code now uses PHP’s native SimpleXML object library to parse all three flavors of RSS (0.92, 1.0, and 2.0) or ATOM feeds. Namespacing, XPATH, and attributes, oh my!

Another improvement fixes a small but annoying issue where strange characters would show up in place of em dashes, curly quotes, and other types of punctuation. These odd and ugly characters were caused by a difference in character encoding between the RSS feed and the LGF page where it’s being displayed. Rewriting everything to use my own RSS parsing code instead of an external library (like SimplePIE or MagpieRSS) helped me figure out the real reason for the problem. Once I understood it, the solution was amazingly simple. Just one line of code using the iconv function to convert the characters from UTF-8 to ISO-8859-1 encoding:

$theString = iconv(“UTF-8”, “ISO-8859-1//TRANSLIT”, $theString);

The server-side PHP script also needs to send a ‘Content-Type’ header to set the character encoding to ISO-8859-1, before sending the formatted RSS data back to the calling Javascript routine. This ensures that all of our lovingly parsed characters look presentable.

header(“Content-Type: text/html; charset=iso-8859-1”);

My RSS script caches the HTML output of each feed for 30 minutes, to avoid abusing anyone’s bandwidth. But if you’re really craving the hottest, freshest news, you can manually refresh the feed before that time limit by clicking the ‘Reload’ button next to the drop-down list.

Jump to top

Create a PageThis is the LGF Pages posting bookmarklet. To use it, drag this button to your browser's bookmark bar, and title it 'LGF Pages' (or whatever you like). Then browse to a site you want to post, select some text on the page to use for a quote, click the bookmarklet, and the Pages posting window will appear with the title, text, and any embedded video or audio files already filled in, ready to go.
Or... you can just click this button to open the Pages posting window right away.
Last updated: 2023-04-04 11:11 am PDT
LGF User's Guide RSS Feeds

Help support Little Green Footballs!

Subscribe now for ad-free access!Register and sign in to a free LGF account before subscribing, and your ad-free access will be automatically enabled.

Donate with
PayPal
Cash.app
Recent PagesClick to refresh
Once Praised, the Settlement to Help Sickened BP Oil Spill Workers Leaves Most With Nearly Nothing When a deadly explosion destroyed BP’s Deepwater Horizon drilling rig in the Gulf of Mexico, 134 million gallons of crude erupted into the sea over the next three months — and tens of thousands of ordinary people were hired ...
Cheechako
Yesterday
Views: 59 • Comments: 0 • Rating: 0
Texas County at Center of Border Fight Is Overwhelmed by Migrant Deaths EAGLE PASS, Tex. - The undertaker lighted a cigarette and held it between his latex-gloved fingers as he stood over the bloated body bag lying in the bed of his battered pickup truck. The woman had been fished out ...
Cheechako
4 days ago
Views: 163 • Comments: 0 • Rating: 1