Search code examples
phpcharacter-encodinghtmlspecialchars

Which charset considering functions changed from PHP5.2 to PHP5.4


When having a file saved in ISO-8859-1 and using the command

echo "test: ".htmlspecialchars("äöü");

The return will be only "test: ".

This is because the standard charset for htmlspecialchars changed to UTF-8 in PHP5.4. You need to explicitly set the charset:

echo "test: ".htmlspecialchars("äöü", ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');

Are there any other functions in PHP5.4, that will not work properly anymore, if you do not set the charset?


Solution

  • htmlentities seems to be another function that was changed: http://de3.php.net/manual/de/migration54.other.php

    The migration guide from PHP 5.2->5.3 does not give any more functions that changed the default charset: http://de3.php.net/manual/de/migration53.php

    So probably it is only htmlspecialchars() and htmlentities

    Anyway, I think those two should definitely go to the "Backward Incompatible Changes"-list http://de3.php.net/manual/de/migration54.incompatible.php