Differences between iconv and mb_convert_encoding encoded strings in php
Source: Internet
Author: User
Description of the differences between iconv and mb_convert_encoding in php conversion strings. For more information, see. Iconv-Convert string to requested character encoding (PHP 4> = 4.0.5, PHP 5)
Mb_convert_encoding-Convert character encoding (PHP 4> = 4.0.6, PHP 5)
Usage:
String mb_convert_encoding (string str, string to_encoding [, mixed from_encoding])
Enable the mbstring extension Library first. in php. ini, remove the extension before php_mbstring.dll.
String iconv (string in_charset, string out_charset, string str)
Note:
The second parameter, in addition to specifying the encoding to be converted, can also add two suffixes: // transcoder and // IGNORE,
Where:
// Transcoder automatically converts a character that cannot be directly converted into one or more similar characters,
// IGNORE ignores the characters that cannot be converted. by default, it is truncated from the first invalid character.
Returns the converted string or FALSE on failure.
Usage:
1. it is found that iconv will encounter an error when converting the character "-" to gb2312. if the ignore parameter is not available, all strings after this character cannot be saved. Either way, this
"-" Cannot be converted successfully, and cannot be output. In addition, mb_convert_encoding does not have this bug.
2. mb_convert_encoding can specify multiple input encodings, which are automatically identified based on the content, but the execution efficiency is much lower than iconv; for example: $ str =
Mb_convert_encoding ($ str, "euc-jp", "ASCII, JIS, EUC-JP, SJIS, UTF-8"); "ASCII, JIS, EUC-JP, SJIS, the order of UTF-8 has different effects
Difference
3. generally, iconv is used. the mb_convert_encoding function is used only when the encoding of the original encoding cannot be determined or The iconv cannot be displayed normally after conversion.
.
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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.