What are the best practices for converting semicolons to commas in a CSV file before downloading it for further processing in PHP?

When working with CSV files in PHP, it's common to encounter semicolons used as delimiters instead of commas. To convert semicolons to commas in a CSV file before downloading it for further processing, you can read the file, replace all semicolons with commas, and then output the modified content to the user for download.

<?php
$file = 'example.csv';
$csv_data = file_get_contents($file);
$csv_data = str_replace(';', ',', $csv_data);

header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="converted.csv"');
echo $csv_data;
exit;
?>