Added better support for encoding problems when escaping a string (available as of PHP 5.4)

| Q             | A
| ------------- | ---
| Bug fix?     | no
| Security fix?   | yes
| New feature?  | no
| Tests pass?   | yes
| License       | MIT