I am developing a Facebook Iframe application using PHP which opens an RSS feed from another site and displays a selected item from the feed. The RSS feed if UTF-8 encoded, however when I display the selected item I get the characters displayed as ISO-8859 whatever.
Example: “Don’t” instead of “Don’t”
This is my working code:
$doc = new DOMDocument();
$doc->load('https://www.otherwebsite.com/rss.php');
foreach ($doc->getElementsByTagName('item') as $node) {
$title = $node->getElementsByTagName('title')->item(0)->nodeValue;
if ($title == $chinese->getAnimal()){
$horoscope = $node->getElementsByTagName('description')->item(0)->nodeValue;
}
}
echo 'Your horoscope : ' . $horoscope . '
';
}
I am using version 5.2 of PHP. Any questions or suggestions will be gratefully accepted, I am still learning PHP so I may have missed something obvious to a more skilled practitioner.
Ensure you have a proper html header and meta for UTF-8 on your webpage i.e.:
Also try casting the string to UTF-8 before echoing it.