What are the common issues with displaying UTF-8 characters in Excel when opening CSV files?

When opening CSV files with UTF-8 characters in Excel, common issues include garbled text or incorrect character encoding. To solve this problem, you can add a Byte Order Mark (BOM) at the beginning of the CSV file to indicate that it is encoded in UTF-8. This will help Excel correctly interpret and display the UTF-8 characters.

// Add BOM to indicate UTF-8 encoding
$csv = "\xEF\xBB\xBF" . $csv_data;

// Output CSV file
header('Content-Encoding: UTF-8');
header('Content-Type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="output.csv"');
echo $csv;