Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the Chinese garbled code in php bom

2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report