在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');