Home > Backend Development > PHP Tutorial > Examples of php encoding conversion methods

Examples of php encoding conversion methods

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:53:52
Original
851 people have browsed it
  1. $content = iconv("gbk", "utf-8", $content); //The first one is simple and easy to use
  2. $content = mb_convert_encoding($content, "utf-8", "gbk" );//The second way to avoid accidents
Copy code

//I found that iconv would make an error when converting the character "—" to gb2312. Without the ignore parameter, all strings following this character cannot be saved. . No matter what, this "-" cannot be converted successfully and cannot be output. In addition, mb_convert_encoding does not have this bug.

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. utf-8 encoding to gbk

  1. $content = iconv("utf-8","gbk", $content); //The first one is simple and easy to use
  2. $content = mb_convert_encoding($content,"gbk","utf-8 ");//The second method avoids accidents
Copy code

Format reference string iconv ( string $in_charset , string $out_charset , string $str ) string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )



Related labels:
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