Home >php教程 >PHP源码 >PHP转换字符串编码

PHP转换字符串编码

PHP中文网
PHP中文网Original
2016-05-25 17:09:25938browse

php代码

<?php
function phpcharset($data, $to) {
	if(is_array($data)) {
		foreach($data as $key => $val) {
			$data[$key] = phpcharset($val, $to);
		}
	} else {
		$encode_array = array(&#39;ASCII&#39;, &#39;UTF-8&#39;, &#39;GBK&#39;, &#39;GB2312&#39;, &#39;BIG5&#39;);
		$encoded = mb_detect_encoding($data, $encode_array);
		$to = strtoupper($to);
		if($encoded != $to) {
			$data = mb_convert_encoding($data, $to, $encoded);
		}
	}
	return $data;
}
?>
Statement:
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