在discuz论坛中广泛用到 htmlspecialchars 这个PHP自带的函数。 该函数在UTF-8版本的Discuz中没有任何问题。 但在GBK版本中问题就大了。 该问题导致如果Discuz用的是GBK版本,且PHP版本在php5.4.x / php5.5.x 中,该函数将导致返回空内容[中文内容情况下]
原因在于 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.
For the purposes of this function, the encodings ISO-8859-1, ISO-8859-15, UTF-8, cp866, cp1251, cp1252, and KOI8-R are effectively equivalent, provided the string itself is valid for the encoding, as the characters affected by htmlspecialchars() occupy the same positions in all of these encodings.
$encoding 在 php5.4.0开始,默认为UTF-8,那GBK的版本如果不调整默认参数,即UTF-8,那调用这个函数取得的中文内容,就会取回空值 典型例子:uc_client/lib/uccode.class.php complie 方法 - function complie($message) {
- $message = htmlspecialchars($message);//该函数将把$message变量清空,原因是传入的不是UTF-8字符
- if(strpos($message, '
复制代码 ') !== FALSE) {
$message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "\$this->codedisp('\\1')", $message);
}[/code]
昨天在升级了php5.5后,发现短消息内容为空,发英文没问题,发中文则为空的情况。
希望官方能处理下GBK版本的Discuz的问题
|