今天項目升級到php5.4,gbk編碼,htmlspecialchars轉換後的字符串為空,郁悶啊
解決,加上編碼吧,這麼多地方用到htmlspecialchars,改起來真麻煩,看來以後得自己封裝一下了。
UPGRADING說到
[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.
手冊中也說到
[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.