|
問題現(xiàn)象:
后臺用戶管理搜索用戶然后導(dǎo)出,導(dǎo)出的用戶數(shù)比實際的少
問題分析:
Discuz! 函數(shù)中的使用的是diconv函數(shù)進行的轉(zhuǎn)換,通過調(diào)試發(fā)現(xiàn)轉(zhuǎn)換為GBK編碼的時候使用iconv函數(shù)進行轉(zhuǎn)換時,字符被截取了。但是 $out = iconv($in_charset, $out_charset.'//IGNORE', $str); 是帶有 ‘//IGNORE ’ 代表遇到轉(zhuǎn)換不了的字符忽略,然而還是被截取了。最后查資料發(fā)現(xiàn)是iconv的bug,將iconv從‘glibc’ 更改為 ‘libiconv ’ (重新編譯iconv模塊) 或者,使用 mb_convert_encoding來進行轉(zhuǎn)換
解決方法:
1、 Linux環(huán)境重新編譯iconv, 從‘glibc’ 更改為 ‘libiconv ’ (具體編譯請到網(wǎng)上搜索相關(guān)資料)
2、使用mb_convert_encoding 代替 iconv
打開:source/function/function_core.php- function diconv($str, $in_charset, $out_charset = CHARSET, $ForceTable = FALSE) {
- global $_G;
- $in_charset = strtoupper($in_charset);
- $out_charset = strtoupper($out_charset);
- if(empty($str) || $in_charset == $out_charset) {
- return $str;
- }
- $out = '';
- if(!$ForceTable) {
- if(function_exists('iconv')) {
- $out = iconv($in_charset, $out_charset.'//IGNORE', $str);
- } elseif(function_exists('mb_convert_encoding')) {
- $out = mb_convert_encoding($str, $out_charset, $in_charset);
- }
- }
- if($out == '') {
- $chinese = new Chinese($in_charset, $out_charset, true);
- $out = $chinese->Convert($str);
- }
- return $out;
- }
復(fù)制代碼 更改為:- function diconv($str, $in_charset, $out_charset = CHARSET, $ForceTable = FALSE) {
- global $_G;
- $in_charset = strtoupper($in_charset);
- $out_charset = strtoupper($out_charset);
- if(empty($str) || $in_charset == $out_charset) {
- return $str;
- }
- $out = '';
- if(!$ForceTable) {
- if(function_exists('mb_convert_encoding')) {
- $out = mb_convert_encoding($str, $out_charset, $in_charset);
- }elseif(function_exists('iconv')) {
- $out = iconv($in_charset, $out_charset.'//IGNORE', $str);
- }
- }
- if($out == '') {
- $chinese = new Chinese($in_charset, $out_charset, true);
- $out = $chinese->Convert($str);
- }
- return $out;
- }
復(fù)制代碼 提示: 使用mb_convert_encoding 函數(shù)需要開啟mbstring模塊
|
|