Strange Characters in your RSS feeds when you try to display them? Fix it!
Tuesday, November 24th, 2009If you have been working with RSS feeds chances are you’ve come across strange characters like “” and struggled to make them go away — we all have.
First you try and preg match them all…. but different ones keep popping up. And of course by the time you are done you are convinced that all these jerks that put -’s, %,^,*,@,!, and ~ in their posts are just out to get YOU personally. They are… get over it.
While you deal with that little fact, time to learn a little about the iconv function. Of course if you actually search for a way to get rid of all those strange characters in your rss feeds you find a lot of crap that isn’t very helpful. You ‘probably’ need the iconv function to get anywhere with the encoding problems you will experience when you try and scrape and display rss feeds…..
Here is a little example ($rss being the content you are converting):
$rss = iconv(“UTF-8″, “ISO-8859-1″, $rss);
The rest of the docs are on php.net – go read up.
Popularity: 1% [?]


Bruce says:
November 26th, 2009
1:54 am
Great post about ICONV
One thing that people may have to keep in mind when using this function is that their installation of PHP may not be correctly installed, especially if using shared hosting.
So to mke sure this works, I would suggest adding the following line somewhere in your PHP code
setlocale(LC_ALL, ‘en_US.UTF8′);
Thanks for the great post
Bruce
admin says:
November 26th, 2009
2:09 am
Thanks for that tip – I don’t have any more shared hosts so I haven’t experienced that at all.