PHP中的iconv()和mb_convert_encoding()有什么区别? [英] What is the difference between iconv() and mb_convert_encoding() in PHP?

查看:247
本文介绍了PHP中的iconv()和mb_convert_encoding()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中的 iconv() mb_convert_encoding()有何区别?一个执行更好,更快等(例如,使用特定的编码)?



这是我认为我已经知道的:



strong> iconv()


  1. 包含在大多数PHP安装中。

  2. 无法映射到新字符集的字符,您可以指定是否将其转换为相似字符,也可以忽略。

mb_convert_encoding()


  1. 通常需要安装php-mbstring扩展程序。
  2. 能够处理 HTML-ENTITIES ,可转换为网页十六进制代码。

$ b code>只是在运行PHP的系统C库中找到的 iconv()函数的包装器(除非PHP是使用GNU iconv构建的,在这种情况下使用GNU iconv)。因此, iconv()的性能和功能取决于您运行PHP的位置及其构建方式。



另一方面, mb_convert_encoding()的实现包含在PHP(模块)源中。它包括一个称为libmbfl的库,它处理实际的转换。因此,它工作相同,不管你在哪里运行PHP。此处提供了支持的编码列表: http://php.net/manual/en/mbstring.encodings.php



总而言之,我想你可以说 mb_convert_encoding()使用如果你想支持不同的平台。但是,如果你在Linux上使用 iconv()(例如),那么它支持更多的编码(见 iconv --list iconv()实现,显然。


What's the difference between iconv() and mb_convert_encoding() in PHP? Does one perform better, faster, etc. ( eg. with specific encodings )? In what situations would one be preferred over the other?

Here's what I think I know already:

iconv()

  1. included with most installs of PHP.
  2. 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()

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

Are there other differences?

解决方案

iconv() is just a wrapper around the iconv() function found in the system C library where PHP is running (unless PHP is built with GNU iconv, in which case GNU iconv is used). So the performance and features of iconv() depend on where you are running PHP and how it is built.

The implementation of mb_convert_encoding(), on the other hand, is included in the PHP (module) source. It includes a library called libmbfl which handles the actual conversion. Thus it works the same regardless of where you're running PHP. There is a list of supported encodings here: http://php.net/manual/en/mbstring.encodings.php

So, in summary, I guess you could say that mb_convert_encoding() is more reliable to use if you want to support different platforms. However, if you use iconv() on Linux (for example), then it supports a lot more encodings (see iconv --list).

The relative performance of the functions also depends on the specific iconv() implementation, obviously.

这篇关于PHP中的iconv()和mb_convert_encoding()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆