我是小站长 發表於 2019-6-2 19:10:44

后台搜索用户导出比实际少的问题

<br /><strong>问题现象:</strong><br />&nbsp; &nbsp;&nbsp;&nbsp;后台用户管理搜索用户然后导出,导出的用户数比实际的少<br /><strong>问题分析:</strong><br />&nbsp; &nbsp;&nbsp;&nbsp;Discuz! 函数中的使用的是diconv函数进行的转换,通过调试发现转换为GBK编码的时候使用iconv函数进行转换时,字符被截取了。但是 $out = iconv($in_charset, $out_charset.'//IGNORE', $str);&nbsp;&nbsp;是带有 ‘//IGNORE ’&nbsp;&nbsp;代表遇到转换不了的字符忽略,然而还是被截取了。最后查资料发现是iconv的bug,将iconv从‘glibc’ 更改为&nbsp;&nbsp;‘libiconv ’ (重新编译iconv模块)&nbsp;&nbsp;或者,使用 mb_convert_encoding来进行转换<br /><strong>解决方法:</strong><br />&nbsp; &nbsp; 1、 Linux环境重新编译iconv, 从‘glibc’ 更改为&nbsp;&nbsp;‘libiconv ’ (具体编译请到网上搜索相关资料)<br />&nbsp; &nbsp; 2、使用mb_convert_encoding&nbsp;&nbsp;代替 iconv&nbsp; &nbsp; <br />&nbsp; &nbsp;&nbsp;&nbsp;打开:source/function/function_core.php<ol><li>function diconv($str, $in_charset, $out_charset = CHARSET, $ForceTable = FALSE) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;global $_G;<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$in_charset = strtoupper($in_charset);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$out_charset = strtoupper($out_charset);<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(empty($str) || $in_charset == $out_charset) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return $str;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$out = '';<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(!$ForceTable) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(function_exists('iconv')) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$out = iconv($in_charset, $out_charset.'//IGNORE', $str);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; } elseif(function_exists('mb_convert_encoding')) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$out = mb_convert_encoding($str, $out_charset, $in_charset);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if($out == '') {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $chinese = new Chinese($in_charset, $out_charset, true);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $out = $chinese-&gt;Convert($str);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return $out;<br /><li>}</ol>更改为:<ol><li>function diconv($str, $in_charset, $out_charset = CHARSET, $ForceTable = FALSE) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;global $_G;<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$in_charset = strtoupper($in_charset);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$out_charset = strtoupper($out_charset);<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(empty($str) || $in_charset == $out_charset) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return $str;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$out = '';<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(!$ForceTable) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(function_exists('mb_convert_encoding')) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$out = mb_convert_encoding($str, $out_charset, $in_charset);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }elseif(function_exists('iconv')) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$out = iconv($in_charset, $out_charset.'//IGNORE', $str);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; } <br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if($out == '') {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $chinese = new Chinese($in_charset, $out_charset, true);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $out = $chinese-&gt;Convert($str);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return $out;<br /><li>}</ol>提示: 使用mb_convert_encoding 函数需要开启mbstring模块<br /><br /> <br /><br />iconv<em>, </em>转换<em>, </em>函数<em>, </em>使用<em>, </em>问题

耗子 發表於 2019-6-2 21:00:47

收藏啦~

xzaxza 發表於 2019-6-9 08:41:33

收藏,备用一下
頁: [1]
查看完整版本: 后台搜索用户导出比实际少的问题