Fix escaping of strings containing ISO characters.

PHP 5.4 changed the default encoding for htmlspecialchars and
htmlentities to be UTF-8, but doesn't use default_charset until 5.6.

This commit wraps all uses of these two functions. Fixes #581.