Trouble with RSS XML file and curly quotes

I am reading in this RSS feed from the FDA
http://www.fda.gov/AboutFDA/ContactFDA/StayInformed/RSSFeeds/Recalls/rss.xml

In this file there are several places where there are curly quotes (“”), but after I have read the file in, they get replaced with garbage characters. open quote become “ and closed becomes ”

I have tried just about everything I can think of, but I still end up with garbage.

Below is the simple version of my code.
You can also click here to run it. (as of 9/16/2010, there were several entries that had the bad characters)

http://www.sophiesafefoodguide.com/rss.php

<?php $feed_url = "http://www.fda.gov/AboutFDA/ContactFDA/StayInformed/RSSFeeds/Recalls/rss.xml"; $xml = simplexml_load_file($feed_url); echo "
Reading RSS Feed
\n"; foreach($xml->channel->item as $entry) { echo "
Entry
\n"; echo "$entry->title
\n"; echo "$entry->link
\n"; echo "$entry->description
\n"; echo "$entry->guid
\n"; echo "$entry->pubDate
\n"; } ?>

I’ve tried reading the file in as a string and then creating a SimpleXMLElement object.
I’ve even tried reading it in as just a string and printing it out and still have the same problem.

All I can guess is php is doing some conversion when it’s reading the file in, but I can’t figure out what it is or how to make it stop.

Any help would be appreciated.

Jeff

These characters can be viewed fine in UTF-8. Add this line to your code before outputting any content to browser:

[php]header(“Content-type: text/html; charset=utf-8”);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service