I've created an rss feed for a website, but it has 2 languages - Greek and English. Everything works fine except the rss feed when an item has a title written in Greek.
So I though ok I must change the encoding before parsing the string. I failed 100%.
I have tried every encoding function php provides: iconv, ut8_encode, mb_convert_encoding also mb_detect_encoding strict and not. I also used html entities, but nothing seems to work
The source code generating the rss is this:
function construct_rss($results, $cat = null)
{
if($results == false)
{
exit;
}
header('Content-Type: application/rss+xml charset=UTF-8');
$rssfeed = '<?xml version="1.0" encoding="utf-8" ?>';
$rssfeed .= '<rss version="2.0">';
$rssfeed .= '<channel>';
$rssfeed .= '<title>domain.com RSS feed</title>';
$rssfeed .= '<link>http://www.domain.com</link>';
if($cat == null)
{
$rssfeed .= '<description>Upcoming events</description>';
}
else
{
$rssfeed .= '<description>Upcoming events - ' . $cat . '</description>';
}
$rssfeed .= '<language>en-us</language>';
$rssfeed .= '<copyright>Copyright (C) 2012 domain.com</copyright>';
foreach ($results as $key => $event)
{
$exp = explode(',',$event['vName']);
$vName = $exp[0];
$rssfeed .= '<item>';
$rssfeed .= '<title>' . $event['eTitle'] . ' @ ' . $vName . '</title>';
$rssfeed .= '<description>' . htmlentities('<a href="http://www.domain.com/event.php?eid=' . $event['id'] .'"><img WIDTH="150" HEIGHT="220" style="width:150px;height:220px;padding-bottom:10px;padding-right:10px;" src="http://'.$_SERVER['SERVER_NAME'].'/image.php?source='.urlencode('events/'.$event['folder'].'/images/default/' . $event['file_1']).'&w=150&h=220&out=raw"></a>' . '<p>' . $event['eDescr'] . '</div>') . '</description>';
$rssfeed .= '<link>http://www.'.$_SERVER['SERVER_NAME'].'/events/' . urlencode($event['eCategory']) . '/' .urlencode($event['url']). '</link>';
$rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($event['dStart'] . ' ' . $event['tStart'])) . '</pubDate>';
$rssfeed .= '</item>';
}
$rssfeed .= '</channel>';
$rssfeed .= '</rss>';
echo $rssfeed;
}
And here is a raw output:
<?xml version="1.0" encoding="utf-8" ?><rss version="2.0">
<channel>
<title>domain.com RSS feed</title>
<link>http://www.domai.com</link>
<description>Upcoming events</description>
<language>en-us</language><copyright>Copyright (C) 2012 domain.com</copyright>
<item>
<title>ΕΙΣΒΟΛΕΑΣ & EVERSOR - O μÏθος καταÏÏÎει @ Gagarin 205 Live Music Space</title>
<description><a href="http://www.domain.com/event.php?eid=209"><img WIDTH="150" HEIGHT="220" style="width:150px;height:220px;padding-bottom:10px;padding-right:10px;" src="http://www.comain.com/image.php?source=events%2F985d6bfa8e35df69471b1ecdb9ed187e%2Fimages%2Fdefault%2Feisvo.jpg&w=150&h=220&out=raw"></a><p><p><span style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;">&Epsilon;&Iota;&Sigma;&Beta;&Omicron;&Lambda;&Epsilon;&Alpha;&Sigma; &amp; EVERSOR - "&Omicron; &Mu;&Upsilon;&Theta;&Omicron;&Sigma; &Kappa;&Alpha;&Tau;&Alpha;&Rho;&Rho;&Epsilon;&Epsilon;&Iota;" TOUR LIVE @ &Alpha;&Theta;&Eta;&Nu;&Alpha; (GAGARIN205), &Sigma;&Alpha;&Beta; 22/12</span><br style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;" /><br style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;" /><span style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;">doors open: 20.00</span><br style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;" /><span style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;">ticket price: 10e</span><br style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;" /><span style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;">guests: 12os Pithikos &amp; Hatemost</span><br style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;" /><span style="color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;">opening: Gelws</span></p></div></description><link>http://www.www.domain.com/events/Hip-Hop+Rap/%CE%95%CE%99%CE%A3%CE%92%CE%9F%CE%9B%CE%95%CE%91%CE%A3-EVERSOR-%CE%9F-%CE%9C%CE%A5%CE%98%CE%9F%CE%A3-%CE%9A%CE%91%CE%A4%CE%91%CE%A1%CE%A1%CE%95%CE%95%CE%99-0</link>
<pubDate>Sat, 22 Dec 2012 20:00:00 +0200</pubDate>
</item>
</channel>
</rss>
As you can see the problem is at the item's title.
If anyone could point to a direction or something because I can't figure this one out. I thought by converting $event['eTitle']
encoding it would work but no luck.
EDIT: stored in db as TEXT utf8_general_ci
EDIT 2: this seems to work ->
utf8_encode(htmlentities($event['eTitle'],ENT_COMPAT,'utf-8'))
but on W3C validator I get this error: column 268: XML parsing error: :1:268: undefined entity
and here Is the highlighted section:
EVERSOR - O μÃ\x8fÂ\x8dθ
\x8f and \x8d cause this error. But why?