Home > Backend Development > PHP Tutorial > PHP -- String encoding conversion (automatically identify the original encoding)_PHP tutorial

PHP -- String encoding conversion (automatically identify the original encoding)_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-14 10:11:55
Original
804 people have browsed it

/**  
 * 对数据进行编码转换  
 * @param array/string $data       数组  
 * @param string $output    转换后的编码  
 */  
function array_iconv($data,$output = 'utf-8') {  
    $encode_arr = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP');  
    $encoded = mb_detect_encoding($data, $encode_arr);//自动判断编码  
  
    if (!is_array($data)) {  
        return mb_convert_encoding($data, $output, $encoded);  
    }  
    else {  
        foreach ($data as $key=>$val) {  
            if(is_array($val)) {  
                $data[$key] = array_iconv($val, $input, $output);  
            } else {  
            $data[$key] = mb_convert_encoding($data, $output, $encoded);  
            }  
        }  
    return $data;  
    }  
}  
Copy after login

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477249.htmlTechArticle/*** Convert data to encoding * @param array/string $data array * @param string $output converted encoding*/ function array_iconv($data,$output = utf-8) { $encode_arr = array...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template