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.
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!