XHTML specifications state that certain literal characters must be represented as their entity, as in ", etc. The function htmlentities() only encodes a few of them. I wrote a function that uses an array of all special characters listed in the XHTML specification and the html entity code for it with strtr(). It looks a little something like this (just a sample):
[...]
$entities[chr(248)] = 'ø';
$entities[chr(249)] = 'ù';
$entities[chr(250)] = 'ú';
$entities[chr(251)] = 'û';
$entities[chr(252)] = 'ü';
$entities[chr(253)] = 'ý';
$entities[chr(254)] = 'þ';
$entities[chr(255)] = 'ÿ';
$entities[chr(338)] = 'Œ';
$entities[chr(339)] = 'œ';
[...]
$str = strtr($str, $entities);
Now, I admit I don't know much about character encodings. My site is in standard ISO as are my scripts. I know there are only 255 characters in the basic ISO set but there are additional sets containing characters XHTML needs to be represented by entities. When testing my function it produced utter garbage, replacing some characters, whether they be special or normal letters, with various characters from the array. I eventually found that by removing all characters in the array above 255 the function works fine. Apparently there is a limitation in Chr() that limits its use to characters below 255 only. I was curious to see if anyone knew of any alternative for inserting characters greater than 255.