Edit report at https://bugs.php.net/bug.php?id=61980&edit=1

 ID:                 61980
 Updated by:         ras...@php.net
 Reported by:        yyb8 at vip dot qq dot com
 Summary:            htmlentities and htmlspecialchars do not work with
                     chinese!
-Status:             Open
+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:

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.


Previous Comments:
------------------------------------------------------------------------
[2012-05-09 13:39:17] info at phpjunkyard dot com

Having the same problem with Windows-1250 chars:

<?php
echo PHP_VERSION . '<br />' . PHP_EOL;
echo 'Testing: ' . htmlentities('ščćžđ ŠČĆŽĐ') . '<br />' . PHP_EOL;
echo 'Testing: ' . htmlspecialchars('ščćžđ ŠČĆŽĐ') . '<br />' . 
PHP_EOL;
echo 'Testing: ' . substr('ščćžđ ŠČĆŽĐ', 0) . '<br />' . 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='<a href="test.html">测试页面</a>';
 
echo htmlentities($str);

print nothing.

it is a bug?

Test script:
---------------
$str='<a href="test.html">测试页面</a>'; 
echo htmlentities($str);




------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61980&edit=1

Reply via email to