/** * 字符串转码 utf-8转换成gbk 或者gbk转换成utf-8 ** @param String $string 需要转码的字符串 * @param String $toType 需要转换的字符编码,默认UTF-8 * * @return String 返回转码后的字符串 * */function transCoding($string, $toType = "UTF-8"){if ($toType == "UTF-8") {$string = iconv("GBK", "UTF-8", $string);} else {$string = iconv("UTF-8", "GBK", $string);}return $string;}$re = $this->transCoding('测试','GBK');print_r($re);$res = $this->transCoding($re,'UTF-8');print_r($res);