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

 

 

 

转载于:https://www.cnblogs.com/longdidi/archive/2013/03/06/2946902.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值