/** * Convert non-GBK character set encoding to GBK * * @ Param mixed $ mixed source data * * @ Return mixed GBK format data */ Function charsetToGBK ($ mixed) { If (is_array ($ mixed )){ Foreach ($ mixed as $ k => $ v ){ If (is_array ($ v )){ $ Mixed [$ k] = charsetToGBK ($ v ); } Else { $ Encode = mb_detect_encoding () ($ v, array ('ascii ', 'utf-8', 'gb2312', 'gbk', 'big5 ')); If ($ encode = 'utf-8 '){ $ Mixed [$ k] = iconv ('utf-8', 'gbk', $ v ); } } } } Else { $ Encode = mb_detect_encoding ($ mixed, array ('ascii ', 'utf-8', 'gb2312', 'gbk', 'big5 ')); // Var_dump ($ encode ); If ($ encode = 'utf-8 '){ $ Mixed = iconv ('utf-8', 'gbk', $ mixed ); } } Return $ mixed; } /** * Convert non-UTF-8 character set encoding to UTF-8 * * @ Param mixed $ mixed source data * * @ Return mixed UTF-8 format data */ Function charsetToUTF8 ($ mixed) { If (is_array ($ mixed )){ Foreach ($ mixed as $ k => $ v ){ If (is_array ($ v )){ $ Mixed [$ k] = charsetToUTF8 ($ v ); } Else { $ Encode = mb_detect_encoding ($ v, array ('ascii ', 'utf-8', 'gb2312', 'gbk', 'big5 ')); If ($ encode = 'euc-cn '){ $ Mixed [$ k] = iconv ('gbk', 'utf-8', $ v ); } } } } Else { $ Encode = mb_detect_encoding ($ mixed, array ('ascii ', 'utf-8', 'gb2312', 'gbk', 'big5 ')); If ($ encode = 'euc-cn '){ $ Mixed = iconv ('gbk', 'utf-8', $ mixed ); } } Return $ mixed; }
?> |