Question: I'm writing some RSS feeds in PHP and stuggling with character-encoding issues. Should I utf8\_encode() before or after htmlentities() encoding? For example, I've got both ampersands and Chinese characters in a description element, and I'm not sure which of these is proper:

```
$output = utf8_encode(htmlentities($source)); or
$output = htmlentities(utf8_encode($source));

```

And why?

Answer: 
It might be easier to forget htmlentities and use a CDATA section. It works for the title section, which doesn't seem support encoded HTML characters in Firefox's RSS viewer:

```
<title><![CDATA[News & Updates  " > » ☂ ☺ ☹ ☃  Test!]]></title>

```
After much trial & error, I finally found a way to properly display a string from a utf8-encoded database value, through an xml file, to an html page:

```
$output = '<![CDATA['.utf8_encode(htmlentities($string)).']]>';

```

I hope this helps someone.