Home > Backend Development > PHP Tutorial > A brief analysis of string encoding conversion in PHP (automatic identification of original encoding)_PHP Tutorial

A brief analysis of string encoding conversion in PHP (automatic identification of original encoding)_PHP Tutorial

WBOY
Release: 2016-07-21 15:01:06
Original
818 people have browsed it

Copy code The code is as follows:

/**
* Convert data to encoding
* @param array/string $data Array
* @param string $output Converted encoding
*/
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);//Automatically determine encoding

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;
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328029.htmlTechArticleCopy the code The code is as follows: /*** Convert data to encoding * @param array/string $data array * @param string $output converted encoding*/ function array_iconv($data,$output = '. ..
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template