What are the best practices for converting character encoding in PHP to ensure compatibility with Excel when exporting data?

When exporting data from PHP to Excel, it is important to ensure that the character encoding is properly converted to UTF-8 to maintain compatibility. To achieve this, you can use the `mb_convert_encoding()` function in PHP to convert the data to UTF-8 before exporting it to Excel.

// Convert data to UTF-8 encoding
$data = mb_convert_encoding($data, 'UTF-8', 'auto');

// Export data to Excel
// Your code to export data to Excel goes here