php的内置函数iconv和mb_convert_encoding都可以用来转换编码
本文讲解是mb_convert_encoding,先来看一下手册的描述:
描述
string mb_convert_encoding ( string str, string to_encoding [, mixed from_encoding] )
mb_convert_encoding() converts character encoding of string str from from_encoding to to_encoding.
str : String to be converted.
from_encoding is specified by character code name before conversion. it can be array or string - comma separated enumerated list. If it is not specified, the internal encoding will be used.
以下是编码转换例子
GBK To UTF-8
<?php
header("content-Type: text/html; charset=Utf-8");
echo mb_convert_encoding("你是我的朋友", "UTF-8", "GBK");
?>
GB2312 To Big5
<?php
header("content-Type: text/html; charset=big5");
echo mb_convert_encoding("你是我的朋友", "big5", "GB2312");
?>