PHP编码转换函数 mb_convert_encoding 与 iconv

本文对比了PHP中两种常用的字符编码转换函数:iconv()和mb_convert_encoding()。iconv()通常随大多数PHP安装包自带,当遇到无法映射到新字符集的字符时,可以指定将其转换为类似的字符或忽略。而mb_convert_encoding()通常需要额外安装php-mbstring扩展,其特色在于能够处理HTML实体,实现与网页十六进制代码之间的相互转换。
string mb_convert_encoding( string $str , string $to_encoding [, mixed $from_encoding ] )
  Returns the encoded string.

string iconv( string $in_charset , string $out_charset , string $str )
  Returns the converted string or FALSE on failure. 

 

What is the difference between iconv() and mb_convert_encoding() in PHP?

 

iconv()
    included with most installs of PHP.
    when characters that can't be mapped to the new character set are found, you can specify if they are converted to a 'similar' character, or ignored.

mb_convert_encoding()

    usually requires installing the php-mbstring extension.
    is able to handle HTML-ENTITIES, converting to and from web hex codes.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值