PHP generated UTC-8 encoded CSV file, using Excel to open the view garbled, share the next solution for your reference. OpenOffice Open Normal and Excel open not normal, later only after the conversion of the code to be resolved. Later, the reason is because there is no BOM in the output CSV file. What is a BOM? There is a character called "ZERO WIDTH no-break SPACE" in the UCS encoding, and its encoding is Feff. Fffe is not a character in UCS, so it should not appear in the actual transmission. The UCS specification recommends that the character "ZERO WIDTH no-break SPACE" be transmitted before the byte stream is transmitted. This means that if the recipient receives Feff, the byte stream is Big-endian, and if Fffe is received, it indicates that the byte stream is Little-endian. So the character "ZERO WIDTH no-break SPACE" is also called a BOM. The UTF-8 does not require a BOM to indicate byte order, but it can be used to indicate the encoding using a BOM. The UTF-8 code for the character "ZERO WIDTH no-break SPACE" is the EF BB BF. So if the receiver receives a byte stream beginning with the EF BB BF, it knows that this is UTF-8 encoded. Windows uses a BOM to mark the way a text file is encoded. So how do you output the BOM in PHP? Before all content output: print (Chr (0xEF). chr (0xBB). Chr (0xBF)); |