php字符串编码转换小例子
时间:2021-07-01 10:21:17
帮助过:6人阅读
- function phpcharset($data, $to) {
- if(is_array($data)) {
- foreach($data as $key => $val) {
- $data[$key] = phpcharset($val, $to);
- }
- } else {
- $encode_array = array('ascii', 'utf-8', 'gbk', 'gb2312', 'big5');
- $encoded = mb_detect_encoding($data, $encode_array);
- $to = strtoupper($to);
- if($encoded != $to) {
- $data = mb_convert_encoding($data, $to, $encoded);
- }
- }
- return $data;
- }
- ?>
|