php htmlspecialchars 输出为空的缘由

在php 5.3.5升为5.6后,部分程序代码的中htmlspecialchars输出为空,究其缘由是php

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.

原来是ISO-8859-1,5.4后默认变成utf-8!而后中文使用这个函数就输出为空白了。html

解决方案是:函数

htmlspecialchars($str,ENT_COMPAT,'GB2312');
相关文章
相关标签/搜索