How to convert binary to utf8 in php

藏色散人
Release: 2023-03-13 18:28:01
Original
3440 people have browsed it

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 )
Copy after login

Example:

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

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!

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