I have a script that downloads results from a MySql table into an CSV file like so
$result = $sql2;
$num_fields = mysql_num_fields($result);
$headers = array();
for ($i = 0; $i < $num_fields; $i++) {
$headers[] = mysql_field_name($result , $i);
}
$fp = fopen('php://output', 'w');
if ($fp && $result) {
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="export.csv"');
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($fp, $headers);
while ($row = mysql_fetch_assoc($result)) {
fputcsv($fp, array_values($row));
}
die;
}
Which works fine, the problem i am having is some of the values of columns contain & quot;. When printing this data on to the web page it shows as a real quote " but when downloading it into the CSV it prints as & quote;. I have tried to htmlspecialchars_decode() but the problem is still there.
Any help will be appreciated.