php字符编码转换之gb2312转为utf8(2)


<?php 
 $content = iconv("GBK", "UTF-8", $content); 
 $content = mb_convert_encoding($content, "UTF-8", "GBK"); 
?>


这个可以根据输入输出的字符编码进行转换

复制代码 代码如下:


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

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/e15dc322df1f759cc222af05f31a5eac.html