PHP encoding conversion function example solution

WBOY
Release: 2016-07-25 08:53:56
Original
920 people have browsed it
  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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!