Home  >  Article  >  Backend Development  >  PHP character encoding conversion problem mb_convert_encoding and iconv function

PHP character encoding conversion problem mb_convert_encoding and iconv function

WBOY
WBOYOriginal
2016-07-25 08:53:44994browse
  1. header("content-type: text/html; charset=utf-8");
  2. echo mb_convert_encoding("You are my friend", "utf-8", "gbk ");
  3. ?>
Copy code

gb2312 to big5 encoding conversion:

  1. header("content-type: text/html; charset=big5");
  2. echo mb_convert_encoding("You are my friend", "big5", "gb2312");
  3. ?>
Copy code

If you use the above function, you need to install it but you need to enable the mbstring extension library first.

string mb_convert_encoding (string str, string to_encoding [, mixed from_encoding]) You need to enable the mbstring extension library first. In php.ini, add; extension=php_mbstring.dll in front of; to remove mb_convert_encoding. You can specify multiple input encodings, which will be based on the content. Automatic recognition, but the execution efficiency is much worse than iconv;

string iconv (string in_charset, string out_charset, string str) Note: In addition to specifying the encoding to be converted to, the second parameter can also add two suffixes: //translit and //ignore, where //translit will automatically convert characters that cannot be directly converted into one or more Approximate characters, //ignore will ignore characters that cannot be converted, and the default effect is to truncate from the first illegal character.

In general, use iconv. Only use the mb_convert_encoding function when you are unable to determine what the original encoding is, or when iconv cannot be displayed normally after conversion.

  1. $content = iconv("gbk", "utf-8″, $content);
  2. $content = mb_convert_encoding($content, "utf-8″, "gbk");
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn