Tech Note: RSS Reader Rewritten

Charles Johnsonfollow me on twitter
Technology • Fri Nov 13, 2009 at 3:36 pm PST • Views: 350

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 ^

Name:

Pass:

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

Turn off ads by subscribing!
For about 33 cents a day, our subscription option turns off all advertisements at LGF!
Read more...


► LGF Headlines

  • Loading...

► Tweeted Articles

  • Loading...

► Tweeted Pages

  • Loading...

► Top 10 Comments

  • Loading...

► Bottom Comments

  • Loading...

► Recent Comments

  • Loading...

► Tools/Info

► 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

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.

The solution remains elusive.

TwitterFacebook
LGF Pages
Recent Pages

MikeySDCA
American Community Survey: Why Republican Hate It.
57 minutes ago
Views: 29 • Comments: 0
Tweets: 0 • Rating: 1

researchok
'I Was Looking Forward to a Quiet Old Age': Instead, Etta Shiber, Helped Smuggle Stranded Allied Soldiers To Freedom
12 hours, 28 minutes ago
Views: 155 • Comments: 0
Tweets: 1 • Rating: 0

Daniel Ballard
Late Afternoon Light-Kalanchoe
20 hours, 9 minutes ago
Views: 143 • Comments: 0
Tweets: 0 • Rating: 5

Eclectic Infidel
City College of San Francisco Budget Update
21 hours, 1 minute ago
Views: 158 • Comments: 0
Tweets: 0 • Rating: 0

Michael McBacon
Kansas governor signs 'Shariah bill' to ban Islamic law
1 day, 1 hour ago
Views: 289 • Comments: 7
Tweets: 0 • Rating: 6

Aigle
National Geographic Traveler Veers Off Track
2 days, 1 hour ago
Views: 632 • Comments: 11
Tweets: 20 • Rating: -7

MichaelJ
Apple TV Slated to Debut in December?
2 days, 2 hours ago
Views: 255 • Comments: 0
Tweets: 0 • Rating: 1

Ascher
Israeli Who Saved Turk on Everest: You Never Abandon a Friend - Israel News, Ynetnews
2 days, 4 hours ago
Views: 325 • Comments: 1
Tweets: 0 • Rating: 4

Haywood Jabloeme
The Harrassment of Patterico & Its Roots in Left-Wing Activism
2 days, 4 hours ago
Views: 560 • Comments: 2
Tweets: 0 • Rating: 4

Curt
Brian Banks: (Video) Falsely accused of rape speaks out
2 days, 6 hours ago
Views: 301 • Comments: 3
Tweets: 0 • Rating: 5

 Frank says:

You can tell what they think of our music by the places we are forced to play it in. This looks like a good spot for a livestock show. -- April 1968, Chicago, Mothers of Invention open for Cream