Home  >  Article  >  Backend Development  >  PHP encoding conversion function example solution

PHP encoding conversion function example solution

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

2, gb2312 to big5 encoding conversion

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

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

Another function iconv in php is also used to convert string encoding, and its function is similar to the function above.

Example:

  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