当前位置:Gxlcms > PHP教程 > php字符串编码转换小例子

php字符串编码转换小例子

时间:2021-07-01 10:21:17 帮助过:6人阅读

  1. function phpcharset($data, $to) {
  2. if(is_array($data)) {
  3. foreach($data as $key => $val) {
  4. $data[$key] = phpcharset($val, $to);
  5. }
  6. } else {
  7. $encode_array = array('ascii', 'utf-8', 'gbk', 'gb2312', 'big5');
  8. $encoded = mb_detect_encoding($data, $encode_array);
  9. $to = strtoupper($to);
  10. if($encoded != $to) {
  11. $data = mb_convert_encoding($data, $to, $encoded);
  12. }
  13. }
  14. return $data;
  15. }
  16. ?>

人气教程排行