Fix escaping of strings containing ISO characters.

PHP 5.4 changed the default encoding for htmlspecialchars and htmlentities to be UTF-8, and doesn't use default_charset until 5.6.

This commit replaces all uses of those two functions with wrapper functions.

Fixes #581.