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

This security fix was took from symfony/symfony@053b42158e2f887b54a3e87977303d219530082f
It already had but from the parser.

In this case, why use `htmlentities` instead of `htmlspecialchars` function?