title: php rss feed character encoding multilingual feed items
body: <p>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.</p>
  
  <p>So I though ok I must change the encoding before parsing the string. I failed 100%.</p>
  
  <p>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</p>
  
  <p>The source code generating the rss is this:</p>
  
  <pre><code>function construct_rss($results, $cat = null)
  {
  
      if($results == false)
      {
          exit;
      }
  
      header('Content-Type: application/rss+xml charset=UTF-8');
  
  
      $rssfeed = '&lt;?xml version="1.0" encoding="utf-8" ?&gt;';
      $rssfeed .= '&lt;rss version="2.0"&gt;';
      $rssfeed .= '&lt;channel&gt;';
      $rssfeed .= '&lt;title&gt;domain.com RSS feed&lt;/title&gt;';
      $rssfeed .= '&lt;link&gt;http://www.domain.com&lt;/link&gt;';
      if($cat == null)
      {
          $rssfeed .= '&lt;description&gt;Upcoming events&lt;/description&gt;';
      }
      else
      {
          $rssfeed .= '&lt;description&gt;Upcoming events - ' . $cat . '&lt;/description&gt;';
      }
      $rssfeed .= '&lt;language&gt;en-us&lt;/language&gt;';
      $rssfeed .= '&lt;copyright&gt;Copyright (C) 2012 domain.com&lt;/copyright&gt;';
  
  
      foreach ($results as $key =&gt; $event) 
      {
          $exp = explode(',',$event['vName']);
          $vName = $exp[0]; 
  
          $rssfeed .= '&lt;item&gt;';
          $rssfeed .= '&lt;title&gt;' . $event['eTitle'] . ' @ ' . $vName . '&lt;/title&gt;';
          $rssfeed .= '&lt;description&gt;' . htmlentities('&lt;a href="http://www.domain.com/event.php?eid=' . $event['id'] .'"&gt;&lt;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']).'&amp;w=150&amp;h=220&amp;out=raw"&gt;&lt;/a&gt;' . '&lt;p&gt;' . $event['eDescr'] . '&lt;/div&gt;') . '&lt;/description&gt;';
          $rssfeed .= '&lt;link&gt;http://www.'.$_SERVER['SERVER_NAME'].'/events/' . urlencode($event['eCategory']) . '/' .urlencode($event['url']). '&lt;/link&gt;';
          $rssfeed .= '&lt;pubDate&gt;' . date("D, d M Y H:i:s O", strtotime($event['dStart'] . ' ' . $event['tStart'])) . '&lt;/pubDate&gt;';
          $rssfeed .= '&lt;/item&gt;';
      }
  
      $rssfeed .= '&lt;/channel&gt;';
      $rssfeed .= '&lt;/rss&gt;';
  
      echo $rssfeed;
  
  }
  </code></pre>
  
  <p>And here is a raw output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;&lt;rss version="2.0"&gt;
  &lt;channel&gt;
  &lt;title&gt;domain.com RSS feed&lt;/title&gt;
  &lt;link&gt;http://www.domai.com&lt;/link&gt;
  &lt;description&gt;Upcoming events&lt;/description&gt;
  &lt;language&gt;en-us&lt;/language&gt;&lt;copyright&gt;Copyright (C) 2012 domain.com&lt;/copyright&gt;
  &lt;item&gt;
  &lt;title&gt;Î•Î™Î£Î’ÎŸÎ›Î•Î‘Î£ &amp; EVERSOR - O Î¼ÏÎ¸Î¿Ï‚ ÎºÎ±Ï„Î±ÏÏÎ­ÎµÎ¹ @ Gagarin 205 Live Music Space&lt;/title&gt;
  &lt;description&gt;&amp;lt;a href=&amp;quot;http://www.domain.com/event.php?eid=209&amp;quot;&amp;gt;&amp;lt;img WIDTH=&amp;quot;150&amp;quot; HEIGHT=&amp;quot;220&amp;quot; style=&amp;quot;width:150px;height:220px;padding-bottom:10px;padding-right:10px;&amp;quot; src=&amp;quot;http://www.comain.com/image.php?source=events%2F985d6bfa8e35df69471b1ecdb9ed187e%2Fimages%2Fdefault%2Feisvo.jpg&amp;amp;w=150&amp;amp;h=220&amp;amp;out=raw&amp;quot;&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;p&amp;gt;&amp;lt;p&amp;gt;&amp;lt;span style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot;&amp;gt;&amp;amp;Epsilon;&amp;amp;Iota;&amp;amp;Sigma;&amp;amp;Beta;&amp;amp;Omicron;&amp;amp;Lambda;&amp;amp;Epsilon;&amp;amp;Alpha;&amp;amp;Sigma; &amp;amp;amp; EVERSOR - &amp;quot;&amp;amp;Omicron; &amp;amp;Mu;&amp;amp;Upsilon;&amp;amp;Theta;&amp;amp;Omicron;&amp;amp;Sigma; &amp;amp;Kappa;&amp;amp;Alpha;&amp;amp;Tau;&amp;amp;Alpha;&amp;amp;Rho;&amp;amp;Rho;&amp;amp;Epsilon;&amp;amp;Epsilon;&amp;amp;Iota;&amp;quot; TOUR LIVE @ &amp;amp;Alpha;&amp;amp;Theta;&amp;amp;Eta;&amp;amp;Nu;&amp;amp;Alpha; (GAGARIN205), &amp;amp;Sigma;&amp;amp;Alpha;&amp;amp;Beta; 22/12&amp;lt;/span&amp;gt;&amp;lt;br style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot; /&amp;gt;&amp;lt;br style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot; /&amp;gt;&amp;lt;span style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot;&amp;gt;doors open: 20.00&amp;lt;/span&amp;gt;&amp;lt;br style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot; /&amp;gt;&amp;lt;span style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot;&amp;gt;ticket price: 10e&amp;lt;/span&amp;gt;&amp;lt;br style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot; /&amp;gt;&amp;lt;span style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot;&amp;gt;guests: 12os Pithikos &amp;amp;amp; Hatemost&amp;lt;/span&amp;gt;&amp;lt;br style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot; /&amp;gt;&amp;lt;span style=&amp;quot;color: #333333; font-family: lucida grande, tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 16px;&amp;quot;&amp;gt;opening: Gelws&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&lt;/description&gt;&lt;link&gt;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&lt;/link&gt;
  &lt;pubDate&gt;Sat, 22 Dec 2012 20:00:00 +0200&lt;/pubDate&gt;
  &lt;/item&gt;
  &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>As you can see the problem is at the item's title.</p>
  
  <p>If anyone could point to a direction or something because I can't figure this one out. I thought by converting <code>$event['eTitle']</code> encoding it would work but no luck.</p>
  
  <p><strong>EDIT:</strong> stored in db as TEXT utf8_general_ci</p>
  
  <p><strong>EDIT 2:</strong> this seems to work -> </p>
  
  <p><code>utf8_encode(htmlentities($event['eTitle'],ENT_COMPAT,'utf-8'))</code></p>
  
  <p>but on W3C validator I get this error: column 268: XML parsing error: :1:268: undefined entity</p>
  
  <p>and here Is the highlighted section:</p>
  
  <pre><code>EVERSOR - O &amp;mu;Ã\x8fÂ\x8d&amp;theta;
  </code></pre>
  
  <p>\x8f and \x8d cause this error. But why?</p>