Tech Note: RSS Reader Rewritten

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

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? Account Settings 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

► LGF Hits

► 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

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.

Militarized theocratic sheep police.

TwitterFacebook
LGF Pages
Recent Pages

researchok
Al Qaeda Leader Backs Syrian Revolt Against Assad
32 minutes ago
Views: 23 • Comments: 0
Tweets: 0 • Rating: 1

researchok
Why the World Needs America: Some Argue That Democracy and Free Markets Could Thrive Without U.S. Predominance. Not Likely.
1 hour, 16 minutes ago
Views: 40 • Comments: 0
Tweets: 0 • Rating: 1

researchok
The World's Baby Factory: It's Already the World's Second-Most Populous Country. So Why Is India Turning 75 Year Old Grandmother
1 hour, 19 minutes ago
Views: 42 • Comments: 0
Tweets: 0 • Rating: 1

researchok
Nazi Family Values: Disturbing Keepsakes of the Most Inhumane Figures in History
1 hour, 22 minutes ago
Views: 47 • Comments: 0
Tweets: 0 • Rating: 0

researchok
The Halftime in America Victory Dance
1 hour, 24 minutes ago
Views: 38 • Comments: 0
Tweets: 0 • Rating: 0

researchok
Mitt's Move on Rick
1 hour, 25 minutes ago
Views: 30 • Comments: 0
Tweets: 0 • Rating: 0

researchok
A powerful megachurch's harsh tactics raise questions about how much control churches should have over their members' lives.
1 hour, 26 minutes ago
Views: 53 • Comments: 0
Tweets: 0 • Rating: 0

researchok
'Speed Freak Killer' Was Paid $33,000 to Guide Search for Victims
1 hour, 26 minutes ago
Views: 42 • Comments: 0
Tweets: 0 • Rating: 0

researchok
Too Many Secrets? The intelligence community's classification system is broken.
1 hour, 26 minutes ago
Views: 43 • Comments: 0
Tweets: 0 • Rating: 0

researchok
Outing Iran: An underground railroad for gay and lesbian Iranians runs through Istanbul to the West
1 hour, 27 minutes ago
Views: 54 • Comments: 0
Tweets: 0 • Rating: 0

 Frank says:

Mr Zappa, I am astounded at the courtesy and soft voiced nature of the comments of my friend, the Senator from Tennessee. I can only say that I find your statement to be boorish, incredibly and insensitively insulting to the people who were here previously, that you could manage to give the First Amendment of the Constitution of the United States a bad name, if I felt you had the slightest understanding of it, which I do not. -- - Senator Slade Gorton