Solve the PHP generated UTF-8 encoding CSV file with Excel open garbled problem wrote in fact this problem has been encountered a long time ago, it should be not resolved, at that time, the openoffice was opened normally, while the excel file was not opened normally. after that, the code was not resolved. this again encountered this problem, on the internet some look, solve the PHP generated UTF-8 encoding CSV file opened with Excel garbled problem
In fact, this problem has been encountered for a long time before and should not be solved. at that time, the problem was that openoffice was opened normally while excel was not opened normally. later, it was not solved, so I had to convert the encoding.
I encountered this problem again. I searched online and found the cause in a java article because the output CSV file does not contain BOM.
What is BOM?
There is a character named "zero width no-break space" in the UCS encoding, and its encoding is FEFF. FFFE does not exist in the UCS, so it should not appear in actual transmission. We recommend that you first transmit the character "zero width no-break space" before transmitting the byte stream ". In this way, 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. Therefore, the character "zero width no-break space" is also called BOM.
The UTF-8 does not need BOM to indicate the byte order, but BOM can be used to indicate the encoding method. The UTF-8 code for the character "zero width no-break space" is ef bb bf. So if the receiver receives a byte stream starting with ef bb bf, it will know that this is UTF-8 encoding.
Windows uses BOM to mark the encoding of text files.
So how to output BOM in PHP?
Before all content is output
Print (chr (0xEF). chr (0xBB). chr (0xBF ));?
?