Home  >  Article  >  Backend Development  >  How to convert binary to utf8 in php

How to convert binary to utf8 in php

藏色散人
藏色散人Original
2021-11-08 10:26:513367browse

php solution to convert binary to utf8: 1. Create a PHP sample file; 2. Convert binary data to utf through "iconv('GBK', 'UTF-8', str1);" -8 is enough.

How to convert binary to utf8 in php

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

How does php convert binary to utf8?

php How to convert Chinese in binary data to utf-8

Use the following function:

string iconv ( string $in_charset , string $out_charset , string $str )

Example:

str1 = '汉字'; // 假设此php源文件以GBK编码保存,那么str1就是GBK编码,占4个字节
str2 = iconv('GBK', 'UTF-8', str1); // str2是utf8编码,占6个字节

Note: If your PHP source file has been saved in UTF8 encoding, there is no need to convert it in this way.

Other related functions:

mb_convert_encoding

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert binary to utf8 in php. For more information, please follow other related articles on the PHP Chinese website!

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