We use the Magpie RSS reader to display the list of 'Recent Journal Entries' on the front page. It does its job well, but it sometimes fails to display HTML entities like apostrophes and quotes correctly. Instead, they appear as a '?'. This problem comes up with some frequency on the Magpie mailing list, but I wasn't able to find a working solution there.
As it turns out, Magpie doesn't automatically detect the character encoding of the RSS it reads. You have to manually define the character encoding of both the input RSS and the output XHTML. Since we use UTF-8, adding these two lines of PHP before including Magpie did the trick:
define('MAGPIE_INPUT_ENCODING', 'UTF-8');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
If that doesn't work, you need to check the character encoding yourself. The input encoding is defined RSS file, at the top, in a line like this: <?xml version="1.0" encoding="UTF-8"?>. The output encoding is that of your XHTML page, usually defined in the Content-Type <meta> tag.


February 12th, 2007 at 6:54 pm
This fix didn’t work for me. What did, was defining the output encoding before loading Magpie, as follows:
define(’MAGPIE_OUTPUT_ENCODING’, ‘UTF-8′);
require(’magpierss/rss_fetch.inc’);
Mapgie then spits out UTF-8 encoded characters, which can be converted to HTML entities quite easily, e.g.:
$output = htmlentities($output, ENT_QUOTES, “UTF-8″);
This solution doesn’t require hacking the Magpie source.
Matthew
September 7th, 2007 at 1:30 pm
Thanks Matthew! Your ‘define’ solution worked brilliantly for me (although I had to change the curly single quotes in your comment to straight single quotes, but I’m sure that was a result of the commenting system here and not your intention).
October 9th, 2007 at 1:50 pm
Matthew - thanks for your post you htmlentities call was exactly what I needed…..
January 14th, 2008 at 7:45 am
We have updated our page based on Matthew’s tip with a few modifications. Hope it helps!
March 3rd, 2008 at 8:53 am
Thank you very much for posting this…I believe you’ve just saved me a TON of time.
March 18th, 2008 at 12:35 am
Excellent solution - worked perfectly, thanks for saving me the headache.
April 10th, 2008 at 9:55 pm
Sweet, I was looking for exactly this solution! Thank you!
April 12th, 2008 at 8:02 pm
sweet and easy fix–thanks Nathan and Matthew!
April 13th, 2008 at 10:51 am
Thanks man… it really did the job!
April 19th, 2008 at 6:02 pm
Thanks. Exactly what i needed … after i realized, that magpierss was killing my german umlauts
May 4th, 2008 at 9:11 am
Great work! Thanks!
May 31st, 2008 at 3:11 am
thanks for the quick fix!
August 12th, 2008 at 8:07 am
This worked for me too… Excellent!
September 19th, 2008 at 8:40 am
Thank you!
September 27th, 2008 at 10:02 am
great thanks, worked for me