5

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?

hakre
  • 193,403
  • 52
  • 435
  • 836
R_User
  • 10,682
  • 25
  • 79
  • 120

2 Answers2

1

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

R_User
  • 10,682
  • 25
  • 79
  • 120
  • 2
    I want to add something : PHP 5.4 was suppose to be "PHP 6.0" which was suppose to be full UTF-8, so in a near futur, all functions will be by default set to UTF-8. – David Bélanger Aug 01 '12 at 12:34
  • @David Bélanger: This is very imprecise. There never was PHP 6.0 and PHP 5.4 was never supposed to be PHP 6.0. Also PHP 6.0 - if ever - was supposted to be UTF-16, not UTF-8. – hakre Apr 29 '13 at 09:53
  • @hakre False. See http://smartwebdeveloper.com/php/php-6-features-release-date-hosting-download – David Bélanger Apr 29 '13 at 13:25
  • @DavidBélanger: I don't understand. Doesn't that link actually underlines what I told? Saying that PHP 6 (was if at all) UTF-16 and not UTF-8? And that PHP 6 was dropped? And that PHP 5.4 was not based on PHP 6? Doesn't Johannes instead wrote back in 2010 on 12th of March that PHP 5.4 is based on Trunk? And that Trunk is based on PHP 5.3 and *not* the PHP 6 branch? I'm a little puzzled, maybe you can clarify? – hakre Apr 29 '13 at 13:45
0

For legacy projects in latin1 we substitute htmlspecialchars with the self-made function htmlXspecialchars according to these instructions: http://ufive.unibe.ch/?c=php54entitiesfix&q=&l=e

Stefan
  • 1