我项目中用到的是广发银行清分 , 需要传递gbk格式 , 但是我的代码默认是utf8 我这边项目写法是:mb_convert_encoding($data,'GBK'); $data是我的xml字符串
下面是这个函数的例子
mb_convert_encoding( $str, $encoding1,$encoding2 );
$str,要转换编码的字符串
$encoding1,目标编码,如utf-8,gbk,大小写均可
$encoding2,原编码,如utf-8,gbk,大小写均可 , 可不填写
实例1
<?php
$str='编码';
echo mb_convert_encoding($str, "UTF-8"); //编码转换为utf-8
?>
实例2
<?php
$str='编码';
echo mb_convert_encoding($str, "UTF-8", "GBK"); //已知原编码为GBK,转换为utf-8
?>
实例3
<?php
$str='编码';
echo mb_convert_encoding($str, "UTF-8", "auto"); //未知原编码,通过auto自动检测后,转换编码为utf-8