gbk字符集下输出为空...utf-8下,输出正常。 为什么呢,原因在于5.4.0对这个函数的变化: 复制代码 代码如下: 5.4.0 The default value for the encoding parameter was changed to UTF-8.
原来是什么呢? 复制代码 代码如下: string htmlspecialchars ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = "UTF-8" [, bool $double_encode = true ]]] ) 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.
文档中有写:An empty string activates detection from script encoding (Zend multibyte), default_charset and current locale (see nl_langinfo() and setlocale()), in this order. Not recommended. 大概意思就是:传入空字符串则使用default_charset的编码 1.3.封装一个函数吧...本来htmlspecialchars这个单词一直不好记。 复制代码 代码如下: function htmlout($str) { return htmlspecialchars($str,ENT_COMPAT,"ISO-8859-1"); }
然后去批量替换。 2.直接修改源码,重编译!这也是目前我在线上做的方案。 修改ext/standard/html.c 大概在372行 复制代码 代码如下: /* Default is now UTF-8 */ if (charset_hint == NULL) return cs_utf_8;
把cs_utf_8改成 cs_8859_1 复制代码 代码如下: /* Default is now UTF-8 */ if (charset_hint == NULL) return cs_8859_1;