Changed Default Encoding to UTF-8

As of PHP 5.4.0, the encoding of multiple html_*() functions defaults to UTF-8, where previously it defaulted to ISO-8859-1. This changes the result when the encoding is not explicitly provided:

htmlentities('é');

See execution result.

As of PHP 5.6.0, it defaults to the value of the default_charset INI directive.

Affected functions:

Solution

The simplest solution is to provide the original default values explicitly:

htmlentities('é', ENT_COMPAT, 'ISO-8859-1');

See execution result.

It's potentially dangerous to switch the default_charset INI directive to ISO-8859-1, because other functions and directives depend on it. Setting the default values explicitly will provide the safest solution and the widest compatibility.

See Also