1. 程式人生 > >php utf8編碼和gbk編碼相互轉換

php utf8編碼和gbk編碼相互轉換

1.utf8轉換為gbk

header("Content-type:text/html;charset=UTF-8");
echo $str= 'utf8轉gbk!';
echo '<br />';
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 '<br />';
echo iconv('GB2312', 'UTF-8', $str); //將字串的編碼從GB2312轉到UTF-8

更多內容請參考原文地址:https://www.codelovers.cn/article/20181126172331.html