Edit report at https://bugs.php.net/bug.php?id=61980&edit=1
ID: 61980
Comment by: info at phpjunkyard dot com
Reported by:yyb8 at vip dot qq dot com
Summary:htmlentities and htmlspecialchars do not work with
chinese!
Status: Not a bug
Type: Bug
Package:Unknown/Other Function
Operating System: windows 2003
PHP Version:5.4.3
Block user comment: N
Private report: N
New Comment:
Actually, Windows-1250 is not supported, so to get it to work correctly I used:
Previous Comments:
[2012-05-09 14:13:42] yyb8 at vip dot qq dot com
Thank you for clarification, should have been more careful when reading the
migration guide:
http://php.net/manual/en/migration54.other.php
This works:
I do expect a lot of broken websites/scripts though when non-utf8 websites
start migrating to PHP 5.4.x...
Regards,
Klemen
[2012-05-09 13:58:31] ras...@php.net
Previously htmlspecialchars/htmlentities assumed iso-8859-1, as of PHP 5.4 it
defaults to UTF-8. You can switch the default back to 8859-1 if you like by
setting default_charset in your ini file, but you risk not encoding things
correctly depending on the actual encoding you are feeding the function. Since
these are security-related functions having 8859-1 as the default wasn't a good
idea because in that encoding everything is valid. If your encoding doesn't map
the characters that are special in HTML to the exact same place as iso-8859-1
then you have a security problem.
So you have two ways to solve it. Change the default in your ini file back to
5.3 behaviour, or be explicit and pass the encoding as the 3rd param to the
functions.
[2012-05-09 13:39:17] info at phpjunkyard dot com
Having the same problem with Windows-1250 chars:
' . PHP_EOL;
echo 'Testing: ' . htmlentities('Å¡ÄÄÅ¾Ä Å ÄÄŽÄ') . '' . PHP_EOL;
echo 'Testing: ' . htmlspecialchars('Å¡ÄÄÅ¾Ä Å ÄÄŽÄ') . '' .
PHP_EOL;
echo 'Testing: ' . substr('Å¡ÄÄÅ¾Ä Å ÄÄŽÄ', 0) . '' . PHP_EOL;
?>
substr works fine, htmlentities and htmlspecialchars don't return anything.
Affected: PHP 5.4.X
Works fine in 5.3.X and previous.
Sincerely,
Klemen
[2012-05-09 10:42:10] yyb8 at vip dot qq dot com
Description:
htmlentities and htmlspecialchars do not work with chinese!
$str='æµè¯é¡µé¢';
echo htmlentities($str);
print nothing.
it is a bug?
Test script:
---
$str='æµè¯é¡µé¢';
echo htmlentities($str);
--
Edit this bug report at https://bugs.php.net/bug.php?id=61980&edit=1