If 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.

 

2 Responses to Strange Characters in your RSS feeds when you try to display them? Fix it!

  1. Bruce says:

    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

  2. admin says:

    Thanks for that tip – I don’t have any more shared hosts so I haven’t experienced that at all.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>