首页 > 语言 > PHP > 正文

PHP实现自动识别原编码并对字符串进行编码转换的方法

2024-05-04 23:48:03
字体:
来源:转载
供稿:网友

本文实例讲述了PHP实现自动识别原编码并对字符串进行编码转换的方法。分享给大家供大家参考,具体如下:

/** * 对数据进行编码转换 * @param array/string $data 数组 * @param string $output 转换后的编码 * Created on 2016-7-13 */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) {      $key = array_iconv($key, $output);      if(is_array($val)) {        $data[$key] = array_iconv($val, $output);      } else {      $data[$key] = mb_convert_encoding($data, $output, $encoded);      }    }  return $data;  }}


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选