I'm creating an RSS feed for a site.
I am using SimpleXML to create the XML structure. When I call $xml->asXML();, it throws many warnings:
ErrorException [ Warning ]: SimpleXMLElement::asXML() [simplexmlelement.asxml]: string is not in UTF-8
I'm not sure what this error is. The database table it is reading from is utf8_general_ci. I tried running utf_encode on the string which messed up the strings instead of fixing it.
//First create the XML root
$xml = new SimpleXMLElement('<rss version="2.0"></rss>');
//Create the Channel
$channel = $xml->addChild('channel');
//Construct the feed parameters
$channel->addChild('title', 'CGarchitect Feed');
$channel->addChild('link', Config::get('base_url'));
$channel->addChild('description', 'CGarchitect is the leading online community for architectural visualization professionals.');
$channel->addChild('pubDate', date("D, d M Y H:i:s T"));
//Get the feed items
$nodes = <....snip... >
foreach ($nodes as $node)
{
//Parse the title and description
$title = htmlentities(strip_tags($node->title));
$description = htmlentities(strip_tags($node->description));
$newItem = $channel->addChild('item');
$newItem->addChild('title', $title);
$newItem->addChild('description', $description);
$newItem->addChild('pubDate', date("D, d M Y H:i:s T", $node->published_at));
}
header('Content-Type: application/xhtml+xml');
echo $xml->asXML();
Thanks in advance...
Leonard