php utf8编码和gbk编码相互转换

1.utf8转换为gbk

header("Content-type:text/html;charset=UTF-8");
echo $str= 'utf8转gbk!';
echo '';
echo iconv("UTF-8","gbk//TRANSLIT",$str); //将字符串的编码从UTF-8转到GB2312

2.gbk转utf8

header("Content-type:text/html;charset=GB2312");
echo $str= 'gbk转utf8!';
echo '';
echo iconv('GB2312', 'UTF-8', $str); //将字符串的编码从GB2312转到UTF-8

更多内容请参考原文地址:https://www.codelovers.cn/article/20181126172331.html

 

你可能感兴趣的:(PHP,编码)