Today the project was upgraded to php5.4, gbk encoding, and the string converted by htmlspecialchars is empty, which is very frustrating
To solve it, add encoding. HTMLspecialchars is used in so many places. It is really troublesome to change it. It seems that I will have to encapsulate it myself in the future.
UPGRADING said
[html]
- the default character set for htmlspecialchars() and htmlentities() is
now UTF-8. In previous versions it was ISO-8859-1. Note that changing
Your output charset via the php.ini default_charset directive does not
affect htmlspecialchars/htmlentities unless you are passing "" (an
empty string) as the encoding parameter to your htmlspecialchars/htmlentities
calls.
It is also mentioned in the manual
[html]
string htmlspecialchars ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = 'UTF-8' [, bool $double_encode = true ]]] )
[html]
Defines encoding used in conversion. If omitted, the default value for this argument is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards.