php logo

PHP utf8_encode – RSS Feed with ISO-8859-1

Finding myself annoyed at an RSS feed which was being rendered with the incorrect character encoding, I searched for the proper way to correct the output. I’m sure there are other ways to do it, but the following worked for me.

Using MagpieRSS, i’ve fetched the RSS feed and prepared it for output using a foreach loop. I used the PHP function utf8_encode() to correctly render the charset.

foreach ($rss->items as $item) {
        $href = $item['link'];
        $title = $item['title'];
        print '<li class="rssfeeditem"><a href="' . $href .
'" target="_blank">' . utf8_encode($title) .'</a></li>';

Whatchu do

Leave a Reply

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