Replace unicode characters with corresponding HTML entities in htmlentities

Fixes #1875 and a failing Klein.php test.