How can PHP functions like utf8_decode be utilized to address character encoding issues when working with CSV files for Excel?

When working with CSV files for Excel, character encoding issues can arise when special characters are not properly handled. One way to address this is by using PHP functions like utf8_decode to convert the data from UTF-8 encoding to ISO-8859-1 encoding, which is commonly used by Excel. This conversion ensures that special characters are displayed correctly in Excel.

// Read CSV file
$csvFile = 'example.csv';
$csvData = file_get_contents($csvFile);

// Convert UTF-8 to ISO-8859-1 encoding
$csvData = utf8_decode($csvData);

// Write the converted data back to the CSV file
file_put_contents('converted_example.csv', $csvData);