How can PHP scripts ensure compatibility with ASP.NET applications when generating CSV files?

When generating CSV files in PHP scripts for compatibility with ASP.NET applications, it is important to ensure that the CSV files are formatted correctly. One way to achieve this is by using the UTF-8 encoding for the CSV files, as it is widely supported by both PHP and ASP.NET. Additionally, specifying the correct MIME type when serving the CSV files can help ensure compatibility with ASP.NET applications.

<?php
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');

$data = array(
    array('Name', 'Age', 'Location'),
    array('John Doe', 30, 'New York'),
    array('Jane Smith', 25, 'Los Angeles'),
);

$output = fopen('php://output', 'w');

foreach ($data as $row) {
    fputcsv($output, $row);
}

fclose($output);
?>