php 常用字符编码转换函数整理

inconv()函数:

范例:

inconv('GB2312','UTF-8',$str);//将字符串的编码由gb2312转换为utf-8

inconv_substr($str,1,1,'UTF-8');//按字符个数截取而非字节

$code =inconv_get_encoding();//获取当前页面编码信息

iconv_strlen($str,'UTF-8');//得到设定编码的字符串长度

 

mb_convert_encoding()函数:

范例:

$str = mb_convert_encoding($str,'utf-8');//将字符串转化为utf-8格式

$str = mb_convert_encoding($str,'utf-8','gb2312');//将字符串由gb2312转换为utf-8格式

$str = mb_convert_encoding($str,'utf-8','gb2312,ASCII');自动将gb2312或者ASCII格式转换为utf-8

$str = mb_convert_encoding($str,'utf-8','auto');//auto:ASCII,JIS,UTF-8,EUC-JP,SJIS

 

mb_detect_encoding() 检测当前字符编码

$encode = mb_detect_encoding($str,array('ASCII','UTF-8','GB2312','GBK','BIG5'));

 

其他相关函数:

utf8_encode utf8_decode

urlencode urldecode

json_encode json_decode

 

 

 

posted @ 2013-03-06 20:45  我叫龙弟弟  阅读(410)  评论(0编辑  收藏  举报