Home > Backend Development > PHP Tutorial > Why Won't My UTF-8 CSV Import into Excel for Mac?

Why Won't My UTF-8 CSV Import into Excel for Mac?

DDD
Release: 2024-12-14 09:11:10
Original
753 people have browsed it

Why Won't My UTF-8 CSV Import into Excel for Mac?

Overcoming UTF-8 CSV Import Issues in Excel for Mac

When attempting to output UTF-8 encoded CSV files, users may encounter import errors in Microsoft Excel for Mac. Despite properly configuring the HTTP headers, characters may still be rendered incorrectly.

The elusive solution lies in incorporating the Byte Order Mark (BOM) into the CSV output. The BOM is a three-byte sequence that identifies the encoding of the file. For UTF-8, the BOM is represented by the hexadecimal values EF BB BF.

To include the BOM in the output, simply append the following line of code before echoing the data:

echo "\xEF\xBB\xBF"; // UTF-8 BOM
Copy after login

By incorporating this modification, the CSV file will be imported correctly into Excel for Mac, preserving the UTF-8 encoding and displaying characters accurately.

The above is the detailed content of Why Won't My UTF-8 CSV Import into Excel for Mac?. For more information, please follow other related articles on the PHP Chinese website!

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