php-字符串转换成gb2312-158

//字符串转换方法

public function get_encoding($data,$to)

{

$encode_arr = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP');

$encoded = mb_detect_encoding($data, $encode_arr);

$data = mb_convert_encoding($data,$to,$encoded);

return $data;

}

//字符串转换调用

$array=array();

foreach($Isp as $i){

$i[cnname]=$this->get_encoding($i[cnname],"GB2312");

$array[]=$i;

}

dump($array);


//转换成功

array

 0 =>

   array

     'id' => string '1' (length=1)

     'numbering' => string '001' (length=3)

     'catid' => string '1' (length=1)

     'cnname' => string '中国电信' (length=8)

     'enname' => string 'CT' (length=2)

     'englishname' => string 'China Telecom' (length=13)

     'isdelete' => string '0' (length=1)

     'remarks' => string '' (length=0)

 1 =>

   array

     'id' => string '2' (length=1)

     'numbering' => string '002' (length=3)

     'catid' => string '1' (length=1)

     'cnname' => string '中国联通' (length=8)

     'enname' => string 'CU' (length=2)

     'englishname' => string 'China Unicom' (length=12)

     'isdelete' => string '0' (length=1)

     'remarks' => string '' (length=0)

 2 =>

   array

     'id' => string '3' (length=1)

     'numbering' => string '003' (length=3)

     'catid' => string '1' (length=1)

     'cnname' => string '中国移动' (length=8)

     'enname' => string 'CM' (length=2)

     'englishname' => string 'China Mobile' (length=12)

     'isdelete' => string '0' (length=1)

     'remarks' => string '' (length=0)


本文出自 “yanzi” 博客,谢绝转载!

你可能感兴趣的:(PHP)