Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

在PHP5.4+ PHP5.5+ Discuz! GBK 所有版本都存在的问题

[复制链接]
oopul 发表于 2013-9-1 10:58:05 | 显示全部楼层 |阅读模式
在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 方法
  1. function complie($message) {
  2.                 $message = htmlspecialchars($message);//该函数将把$message变量清空,原因是传入的不是UTF-8字符
  3.                 if(strpos($message, '
复制代码
') !== FALSE) {
                        $message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "\$this->codedisp('\\1')", $message);
                }[/code]
昨天在升级了php5.5后,发现短消息内容为空,发英文没问题,发中文则为空的情况。

希望官方能处理下GBK版本的Discuz的问题

IDC866.com 发表于 2013-9-1 13:33:30 | 显示全部楼层
已经很多人提过了。但是一直没解决。

楼主先还是自己解决吧。  

自己把PHP重新安装一次,在安装PHP的时候去修改一个文件,再安装就可以了。

使用 PHP 5.4 版本需要注意的问题   

让他默认使用 ISO-8859-1 编码。

这样就跟以前的PHP53 环境一样。PW旧程序也完美支持了。连DZ老版都支持了。
回复

使用道具 举报

下砂 发表于 2013-9-2 13:44:00 | 显示全部楼层
问题已反馈
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2025-3-9 09:34 , Processed in 0.024907 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表