Tech Note: RSS Reader Rewritten

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

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.

Just a guy with a toolbox.

TwitterFacebook
LGF Pages
Recent Pages

Daniel Ballard
Iran Hit With 'Flame,' the Most Sophisticated Spy Virus Ever - May. 30, 2012
2 hours, 1 minute ago
Views: 46 • Comments: 0
Tweets: 0 • Rating: 1

researchok
Romney and Trump
3 hours, 32 minutes ago
Views: 62 • Comments: 0
Tweets: 0 • Rating: 0

ggt
Leona's Sister Gerri
4 hours, 36 minutes ago
Views: 60 • Comments: 0
Tweets: 0 • Rating: 1

I AM BREITBART!
Seattle Manhunt Launched After Deadly Cafe Shootings, Carjacking
6 hours, 46 minutes ago
Views: 103 • Comments: 1
Tweets: 0 • Rating: 2

Shiplord Kirel
Dragon to Depart Station Thursday
7 hours, 57 minutes ago
Views: 53 • Comments: 0
Tweets: 0 • Rating: 1

Randall Gross
Citadel Malware Delivers Reveton Ransomware in attempts to extort money
8 hours, 50 minutes ago
Views: 142 • Comments: 0
Tweets: 0 • Rating: 3

Channeling Confucius
From the previous Diamond Jubilee: Kipling's 'Recessional'
9 hours, 21 minutes ago
Views: 89 • Comments: 0
Tweets: 0 • Rating: 0

Bob Dillon
REVEALED: Hundreds of Words to Avoid Using Online if You Don't Want the Government Spying on You
10 hours, 25 minutes ago
Views: 219 • Comments: 3
Tweets: 0 • Rating: 2

Learned Mother of Zion
Native Americans Have Jewish DNA!
10 hours, 45 minutes ago
Views: 336 • Comments: 10
Tweets: 1 • Rating: 8

Eclectic Infidel
Mitt Romney for a better Amercia!
10 hours, 50 minutes ago
Views: 151 • Comments: 1
Tweets: 0 • Rating: 0

 Frank says:

I'm not black, but there's a whole lot of times I wish I could say I'm not white.