这篇文章主要介绍了php5.4以上版本GBK编码下htmlspecialchars输出为空问题解决方法汇总,本文给出多种解决这个问题的方法,需要的朋友可以参考下
从旧版升级到php5.4,恐怕最麻烦的就是htmlspecialchars这个问题了!当然,htmlentities也会受影响,不过,对于中文站来说一般用htmlspecialchars比较常见,htmlentities非常少用到。
可能老外认为网页普遍应该是utf-8编码的,于是苦了那些用GB2312,GBK编码的中文站……!
具体表现:
代码如下:
$str = “9enjoy.com的php版本是5.2.10”;
echo htmlspecialchars($str);
echo htmlspecialchars($str);
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_enc来源gao($daima.com搞@代@#码网ode = 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.
以上就是php5.4以上版本GBK编码下htmlspecialchars输出为空问题解决方法汇总的详细内容,更多请关注gaodaima搞代码网其它相关文章!