首页 > 其他 > 详细

DiscuzX论坛短消息内容显示空白或不能正常显示中文的解决方案

时间:2014-03-14 18:39:20      阅读:662      评论:0      收藏:0      [点我收藏+]

问题描述:在PHP5.4x版本中论坛短消息内容显示空白或不能正常显示中文的解决方案
ucenter在php5.4里,中文短消息无法显示的问题主要是由于uccode.class.php中的htmlspecialchars函数没有经过编码转换,为了解决这个问题,需要对默认的htmlspecialchars进行自定义。

解决方案:


文件:/uc_client/lib/uccode.class.php

查找:function complie($message)

在前面加上:

//解决PHP5.4x版本htmlspecialchars函数中文编码问题
        function cr180_dhtmlspecialchars($string, $flags = null) {
            if(is_array($string)) {
                foreach($string as $key => $val) {
                    $string[$key] = dhtmlspecialchars($val, $flags);
                }
            } else {
                if($flags === null) {
                    $string = str_replace(array(‘&‘, ‘"‘, ‘<‘, ‘>‘), array(‘&amp;‘, ‘&quot;‘, ‘&lt;‘, ‘&gt;‘), $string);
                    if(strpos($string, ‘&amp;#‘) !== false) {
                        $string = preg_replace(‘/&amp;((#(\d{3,5}|x[a-fA-F0-9]{4}));)/‘, ‘&\\1‘, $string);
                    }
                } else {
                    if(PHP_VERSION < ‘5.4.0‘) {
                        $string = htmlspecialchars($string, $flags);
                    } else {
                        if(strtolower(CHARSET) == ‘utf-8‘) {
                            $charset = ‘UTF-8‘;
                        } else {
                            $charset = ‘ISO-8859-1‘;
                        }
                        $string = htmlspecialchars($string, $flags, $charset);
                    }
                }
            }
            return $string;
        }


查找 $message = htmlspecialchars($message);

替换为:$message = $this -> cr180_dhtmlspecialchars($message);


另外,短消息首页无法显示消息内容的问题是由于ucenter函数【lastpm($uid)】里没有提前初始化变量造成的,所以还需要进行以下修改:

文件:/uc_client/model/pm.php

查找:

    function lastpm($uid) {
            $lastpm =
    $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_members m
    LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON m.plid=t.plid WHERE
    m.uid=‘$uid‘ ORDER BY m.lastdateline DESC LIMIT 1");
            $lastmessage = unserialize($lastpm[‘lastmessage‘]);
            if($lastmessage[‘lastauthorid‘]) {
                $lastpm[‘lastauthorid‘] = $lastmessage[‘lastauthorid‘];
                $lastpm[‘lastauthor‘] = $lastmessage[‘lastauthor‘];
                $lastpm[‘lastsummary‘] = $lastmessage[‘lastsummary‘];
            } else {
                $lastpm[‘lastauthorid‘] = $lastmessage[‘firstauthorid‘];
                $lastpm[‘lastauthor‘] = $lastmessage[‘firstauthor‘];
                $lastpm[‘lastsummary‘] = $lastmessage[‘firstsummary‘];
            }
           
            return $lastpm;
        }

替换为:

    function lastpm($uid) {
            $lastpm = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_members m LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON m.plid=t.plid WHERE m.uid=‘$uid‘ ORDER BY m.lastdateline DESC LIMIT 1");
            <font color="Red"><b>$lastmessage = array();//cr180修正 变量初始化 PHP高版本时可能会造成该变量异常</b></font>
            $lastmessage = unserialize($lastpm[‘lastmessage‘]);
            if($lastmessage[‘lastauthorid‘]) {
                $lastpm[‘lastauthorid‘] = $lastmessage[‘lastauthorid‘];
                $lastpm[‘lastauthor‘] = $lastmessage[‘lastauthor‘];
                $lastpm[‘lastsummary‘] = $lastmessage[‘lastsummary‘];
            } else {
                $lastpm[‘lastauthorid‘] = $lastmessage[‘firstauthorid‘];
                $lastpm[‘lastauthor‘] = $lastmessage[‘firstauthor‘];
                $lastpm[‘lastsummary‘] = $lastmessage[‘firstsummary‘];
            }
           
            return $lastpm;
        }

DiscuzX论坛短消息内容显示空白或不能正常显示中文的解决方案,布布扣,bubuko.com

DiscuzX论坛短消息内容显示空白或不能正常显示中文的解决方案

原文:http://www.cnblogs.com/wuxinzhiyuan/p/3598968.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!