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>

```
You want to do `$output = htmlentities(utf8_encode($source));`. This is because you want to convert your international characters into proper UTF8 first, and then have ampersands (and possibly some of the UTF-8 characters as well) turned in to HTML entities. If you do the entities first, then some of the international characters may not be handled properly.

If none of your international characters are going to be changed by utf8\_encode, then it doesn't matter which order you call them in.