Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the Chinese garbled code in php bom

Shulou Source: shulou.com Published: 2022-06-02 09:15:11 09月15日 Update

This article mainly explains "how to solve php bom Chinese garbled code". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to solve php bom Chinese garbled"!

Php bom Chinese garbled solution: 1, open the corresponding PHP development file; 2, add "$bom = pack (" C3 ", 239187191); $strcsv = $bom.$strcsv;".

This article operating environment: windows7 system, PHP7.4 version, DELL G3 computer

What about the Chinese garbled code in php bom?

Garbled code problems caused by BOM in PHP development

In the project, the csv file should be downloaded directly in php, and after the file is downloaded, the garbled code will be displayed in excel. So add BOM as follows:

$bom = pack ("C3", 239187191); / / bom: xEFxBBxBF$strcsv = $bom.$strcsv

The following is a more refined explanation from the Internet:

BOM's description: there is a character called "ZERO WIDTH NO-BREAK SPACE" in the UCS code, which is encoded as FEFF. FEFF is a character that does not exist in UCS, so it should not appear in the actual transmission. The UCS specification recommends that we transfer the character "ZERO WIDTH NO-BREAK SPACE" before transferring the byte stream. Thus, if the receiver receives FEFF, it indicates that the byte stream is Big-Endian; if it receives FFFE, it indicates that the byte stream is Little- Endian. So the character "ZERO WIDTH NO-BREAK SPACE" is also called BOM.

UTF-8 does not need BOM to indicate byte order, but BOM can be used to indicate how it is encoded. The UTF-8 encoding of the character "ZERO WIDTH NO-BREAK SPACE" is EF BB BF. So if the receiver receives a byte stream that starts with EF BB BF, it knows that this is UTF-8 coding. Windows uses BOM to mark the encoding of text files.

PHP was not designed with BOM in mind, which means that he will not ignore the three characters at the beginning of the BOM in the UTF-8-encoded file.

At this point, I believe that everyone on the "php bom Chinese garbled code how to solve" have a deeper understanding, might as well to practical operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Garbled coding character Chinese file UTF-8 method transmission content actual beginning receiver problem learning development practical deeper three that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MariaDB Huawei Docker Redmi