<?php
header("Content-type:text/html;charset=UTF-8");
echo $str= '你好, 这里是 utf8 转 gbk!';
echo '<br />';
echo iconv("UTF-8","gbk//TRANSLIT",$str); // 将字符串的编码从 UTF- 8 转到 GB2312
<?php
header("Content-type:text/html;charset=GB2312");
echo $str= '你好, 这里是 gbk 转 utf8!';
echo '<br />';
echo iconv('GB2312', 'UTF-8', $str); // 将字符串的编码从 GB2312 转到 UTF-8
获取当前字符串的编码
$encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
将字符编码改为 utf-8
$str_encode = mb_convert_encoding($str, 'UTF-8', $encode);