- /**
- * 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;
- }
Encoding format, read the data on the Internet or garbled, try this bar