LGF

more options

  

Advertisement

Tech Note: RSS Reader Rewritten

Technology | Fri, Nov 13, 2009 at 3:36:26 pm PST

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.

Advertisement

539 comments

^ back to top ^

log in
Name:
Pass:

Register Forgot Your Password? My Account Re-send Confirmation (To log in, cookies must be enabled in your browser!)

► LGF Headlines

► Top 10 Comments

► Bottom Comments

► Recent Comments

► Tools/Info

► LGF Hits

► Slideshows

► Resources

► Never Forget

► Statistics

► Tag Cloud

► Contact

You must have Javascript enabled to use the contact form.
Your email:

Subject:

Message:


Messages may be published in our weblog, unless you request otherwise.
Tech Note:
Using the Contact Form

► News/Opinion

More Partners

Compare Electricity Prices in your area. Texas Electricity is deregulated; you have the right to choose Texas Electric Rates from among many Texas Electric Companies.

Buffaloes stupid.


Free Shipping  and up to 30% savings on new Textbooks